<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
  <meta name="theme-color" content="#222">
  <meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/safari-pinned-tab.svg" color="#222">
  <link rel="stylesheet" href="/css/main.css">
  <link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>
  <script id="hexo-configurations">
    var NexT = window.NexT ||
    {};
    var CONFIG = {
      "hostname": "cuiqingcai.com",
      "root": "/",
      "scheme": "Pisces",
      "version": "7.8.0",
      "exturl": false,
      "sidebar":
      {
        "position": "right",
        "width": 360,
        "display": "post",
        "padding": 18,
        "offset": 12,
        "onmobile": false,
        "widgets": [
          {
            "type": "image",
            "name": "阿布云",
            "enable": false,
            "url": "https://www.abuyun.com/http-proxy/introduce.html",
            "src": "https://qiniu.cuiqingcai.com/88au8.jpg",
            "width": "100%"
      },
          {
            "type": "image",
            "name": "天验",
            "enable": true,
            "url": "https://tutorial.lengyue.video/?coupon=12ef4b1a-a3db-11ea-bb37-0242ac130002_cqx_850",
            "src": "https://qiniu.cuiqingcai.com/bco2a.png",
            "width": "100%"
      },
          {
            "type": "image",
            "name": "华为云",
            "enable": false,
            "url": "https://activity.huaweicloud.com/2020_618_promotion/index.html?bpName=5f9f98a29e2c40b780c1793086f29fe2&bindType=1&salesID=wangyubei",
            "src": "https://qiniu.cuiqingcai.com/y42ik.jpg",
            "width": "100%"
      },
          {
            "type": "image",
            "name": "张小鸡",
            "enable": false,
            "url": "http://www.zxiaoji.com/",
            "src": "https://qiniu.cuiqingcai.com/fm72f.png",
            "width": "100%"
      },
          {
            "type": "image",
            "name": "Luminati",
            "src": "https://qiniu.cuiqingcai.com/ikkq9.jpg",
            "url": "https://luminati-china.io/?affiliate=ref_5fbbaaa9647883f5c6f77095",
            "width": "100%",
            "enable": false
      },
          {
            "type": "image",
            "name": "IPIDEA",
            "url": "http://www.ipidea.net/?utm-source=cqc&utm-keyword=?cqc",
            "src": "https://qiniu.cuiqingcai.com/0ywun.png",
            "width": "100%",
            "enable": true
      },
          {
            "type": "tags",
            "name": "标签云",
            "enable": true
      },
          {
            "type": "categories",
            "name": "分类",
            "enable": true
      },
          {
            "type": "friends",
            "name": "友情链接",
            "enable": true
      },
          {
            "type": "hot",
            "name": "猜你喜欢",
            "enable": true
      }]
      },
      "copycode":
      {
        "enable": true,
        "show_result": true,
        "style": "mac"
      },
      "back2top":
      {
        "enable": true,
        "sidebar": false,
        "scrollpercent": true
      },
      "bookmark":
      {
        "enable": false,
        "color": "#222",
        "save": "auto"
      },
      "fancybox": false,
      "mediumzoom": false,
      "lazyload": false,
      "pangu": true,
      "comments":
      {
        "style": "tabs",
        "active": "gitalk",
        "storage": true,
        "lazyload": false,
        "nav": null,
        "activeClass": "gitalk"
      },
      "algolia":
      {
        "hits":
        {
          "per_page": 10
        },
        "labels":
        {
          "input_placeholder": "Search for Posts",
          "hits_empty": "We didn't find any results for the search: ${query}",
          "hits_stats": "${hits} results found in ${time} ms"
        }
      },
      "localsearch":
      {
        "enable": true,
        "trigger": "auto",
        "top_n_per_article": 10,
        "unescape": false,
        "preload": false
      },
      "motion":
      {
        "enable": false,
        "async": false,
        "transition":
        {
          "post_block": "bounceDownIn",
          "post_header": "slideDownIn",
          "post_body": "slideDownIn",
          "coll_header": "slideLeftIn",
          "sidebar": "slideUpIn"
        }
      },
      "path": "search.xml"
    };

  </script>
  <meta name="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
  <meta property="og:type" content="website">
  <meta property="og:title" content="静觅">
  <meta property="og:url" content="https://cuiqingcai.com/page/27/index.html">
  <meta property="og:site_name" content="静觅">
  <meta property="og:description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
  <meta property="og:locale" content="zh_CN">
  <meta property="article:author" content="崔庆才">
  <meta property="article:tag" content="崔庆才">
  <meta property="article:tag" content="静觅">
  <meta property="article:tag" content="PHP">
  <meta property="article:tag" content="Java">
  <meta property="article:tag" content="Python">
  <meta property="article:tag" content="Spider">
  <meta property="article:tag" content="爬虫">
  <meta property="article:tag" content="Web">
  <meta property="article:tag" content="Kubernetes">
  <meta property="article:tag" content="深度学习">
  <meta property="article:tag" content="机器学习">
  <meta property="article:tag" content="数据分析">
  <meta property="article:tag" content="网络">
  <meta property="article:tag" content="IT">
  <meta property="article:tag" content="技术">
  <meta property="article:tag" content="博客">
  <meta name="twitter:card" content="summary">
  <link rel="canonical" href="https://cuiqingcai.com/page/27/">
  <script id="page-configurations">
    // https://hexo.io/docs/variables.html
    CONFIG.page = {
      sidebar: "",
      isHome: true,
      isPost: false,
      lang: 'zh-CN'
    };

  </script>
  <title>静觅丨崔庆才的个人站点</title>
  <meta name="google-site-verification" content="p_bIcnvirkFzG2dYKuNDivKD8-STet5W7D-01woA2fc" />
  <noscript>
    <style>
      .use-motion .brand,
      .use-motion .menu-item,
      .sidebar-inner,
      .use-motion .post-block,
      .use-motion .pagination,
      .use-motion .comments,
      .use-motion .post-header,
      .use-motion .post-body,
      .use-motion .collection-header
      {
        opacity: initial;
      }

      .use-motion .site-title,
      .use-motion .site-subtitle
      {
        opacity: initial;
        top: initial;
      }

      .use-motion .logo-line-before i
      {
        left: initial;
      }

      .use-motion .logo-line-after i
      {
        right: initial;
      }

    </style>
  </noscript>
  <link rel="alternate" href="/atom.xml" title="静觅" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container">
    <div class="headband"></div>
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner">
        <div class="site-brand-container">
          <div class="site-nav-toggle">
            <div class="toggle" aria-label="切换导航栏">
              <span class="toggle-line toggle-line-first"></span>
              <span class="toggle-line toggle-line-middle"></span>
              <span class="toggle-line toggle-line-last"></span>
            </div>
          </div>
          <div class="site-meta">
            <a href="/" class="brand" rel="start">
              <span class="logo-line-before"><i></i></span>
              <h1 class="site-title">静觅 <span class="site-subtitle"> 崔庆才的个人站点 </span>
              </h1>
              <span class="logo-line-after"><i></i></span>
            </a>
          </div>
          <div class="site-nav-right">
            <div class="toggle popup-trigger">
              <i class="fa fa-search fa-fw fa-lg"></i>
            </div>
          </div>
        </div>
        <nav class="site-nav">
          <ul id="menu" class="main-menu menu">
            <li class="menu-item menu-item-home">
              <a href="/" rel="section">首页</a>
            </li>
            <li class="menu-item menu-item-archives">
              <a href="/archives/" rel="section">文章列表</a>
            </li>
            <li class="menu-item menu-item-tags">
              <a href="/tags/" rel="section">文章标签</a>
            </li>
            <li class="menu-item menu-item-categories">
              <a href="/categories/" rel="section">文章分类</a>
            </li>
            <li class="menu-item menu-item-about">
              <a href="/about/" rel="section">关于博主</a>
            </li>
            <li class="menu-item menu-item-message">
              <a href="/message/" rel="section">给我留言</a>
            </li>
            <li class="menu-item menu-item-search">
              <a role="button" class="popup-trigger">搜索 </a>
            </li>
          </ul>
        </nav>
        <div class="search-pop-overlay">
          <div class="popup search-popup">
            <div class="search-header">
              <span class="search-icon">
                <i class="fa fa-search"></i>
              </span>
              <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off" placeholder="搜索..." spellcheck="false" type="search" class="search-input">
              </div>
              <span class="popup-btn-close">
                <i class="fa fa-times-circle"></i>
              </span>
            </div>
            <div id="search-result">
              <div id="no-result">
                <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
              </div>
            </div>
          </div>
        </div>
      </div>
    </header>
    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span>0%</span>
    </div>
    <div class="reading-progress-bar"></div>
    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div class="content index posts-expand">
            <div class="carousel">
              <div id="wowslider-container">
                <div class="ws_images">
                  <ul>
                    <li><a target="_blank" href="https://cuiqingcai.com/5052.html"><img title="Python3网络爬虫开发实战教程" src="https://qiniu.cuiqingcai.com/ipy96.jpg" /></a></li>
                    <li><a target="_blank" href="https://t.lagou.com/fRCBRsRCSN6FA"><img title="52讲轻松搞定网络爬虫" src="https://qiniu.cuiqingcai.com/fqq5e.png" /></a></li>
                    <li><a target="_blank" href="https://brightdata.grsm.io/cuiqingcai"><img title="亮网络解锁器" src="https://qiniu.cuiqingcai.com/6qnb7.png" /></a></li>
                    <li><a target="_blank" href="https://cuiqingcai.com/4320.html"><img title="Python3网络爬虫开发视频教程" src="https://qiniu.cuiqingcai.com/bjrny.jpg" /></a></li>
                    <li><a target="_blank" href="https://cuiqingcai.com/5094.html"><img title="爬虫代理哪家强？十大付费代理详细对比评测出炉！" src="https://qiniu.cuiqingcai.com/nifs6.jpg" /></a></li>
                  </ul>
                </div>
                <div class="ws_thumbs">
                  <div>
                    <a target="_blank" href="#"><img src="https://qiniu.cuiqingcai.com/ipy96.jpg" /></a>
                    <a target="_blank" href="#"><img src="https://qiniu.cuiqingcai.com/fqq5e.png" /></a>
                    <a target="_blank" href="#"><img src="https://qiniu.cuiqingcai.com/6qnb7.png" /></a>
                    <a target="_blank" href="#"><img src="https://qiniu.cuiqingcai.com/bjrny.jpg" /></a>
                    <a target="_blank" href="#"><img src="https://qiniu.cuiqingcai.com/nifs6.jpg" /></a>
                  </div>
                </div>
                <div class="ws_shadow"></div>
              </div>
            </div>
            <link rel="stylesheet" href="/lib/wowslide/slide.css">
            <script src="/lib/wowslide/jquery.min.js"></script>
            <script src="/lib/wowslide/slider.js"></script>
            <script>
              jQuery("#wowslider-container").wowSlider(
              {
                effect: "cube",
                prev: "",
                next: "",
                duration: 20 * 100,
                delay: 20 * 100,
                width: 716,
                height: 297,
                autoPlay: true,
                playPause: true,
                stopOnHover: false,
                loop: false,
                bullets: 0,
                caption: true,
                captionEffect: "slide",
                controls: true,
                onBeforeStep: 0,
                images: 0
              });

            </script>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1547.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> 个人随笔 <i class="label-arrow"></i>
                  </a>
                  <a href="/1547.html" class="post-title-link" itemprop="url">致那逝去的三月</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <p>4月4日，凌晨3点，我依旧无法入眠，心里想了很多，索性起床把现在的所想记录下来。也许，在一觉过后，这些情感或许就无法挥洒出来了。现在，借着那纯音乐，借着那静谧的夜，总结一下那逝去的三月。 三月一日开学，到现在已经有了一个月多一点的时间了，都说大三下是最难熬的一段时光，亲身经历之后才觉得真的是这样，这一个月，可以用浮躁两个字来形容。 浮躁之处在哪？学习，面试，备考，社交，做事还有其他，浮躁之气充斥在方方面面。 大三开始，不得不去考虑工作或是读研的事情，身边的朋友们，有的选择考研，有的选择工作。室友三个，选择的也都是工作。开学之初，各大公司的校招纷纷开始了，朋友们纷纷开始往各大公司投简历，BAT也不例外。当然BAT终究是BAT，不是省油的灯，一些朋友就在这条道路上遭遇了不少的坎坷，有的简历初审就被PASS，有的电面几轮之后也不幸失败，过程非常坎坷。其中有些朋友一份简历投上几十家公司，想碰运气，录用上哪一个是哪一个，而在我看来，这真的没有太大的意义。投一个公司，对该公司有全面的了解是至关重要，而且公司的理念文化适不适合自己去工作也是一个重要的因素，在我看来，这种碰运气的方法，实不可取。 而对于我自己，更加倾向于读研，鉴于自己的学习成绩还算不错，前百分之五，想申请一下保研，查找了各大学校的招生信息，对自己要复习和准备的东西也有了一些把握，可这一个月以来，自己难以静心去学习。其实说来，周围的朋友纷纷在准备找工作实习，而他们的焦点则就放在了填补一些职业相关的专业知识，掌握一些面试技巧，他们一轮轮的电面，也为自己的工作积累了经验。而我，也在想在大四的时候申请一份实习工作，就算没有拿到Offer，在面试的过程中也能积累一部分的经验，索性我也去试试吧。 制作了自己的一份简历，我也投上了BAT和一些其他公司，因为我本身对网页开发比较了解，尤其是后端开发，PHP部分。而像阿里这样的公司，他们的后端不是利用PHP处理的，所以我就报了前端开发的职位。但是自己的前端功底还不太强，所以我就开始补习JS，jQuery等等的知识，这一个月以来，大多数时间就在学习这些知识。对于找工作我可以说是试一试的态度，学习起来感觉沉不住气，而且可能觉得随时会有一个电话面试打过来，所以我觉得难以系统地，静心地去学习这些知识。 其实周围的朋友和我的情况是差不多的，我特意问过他们最近是怎样的状态，他们也回应说，感觉有些浮躁，完全是在一个应试的压力下在学习，对于一些知识只是修修补补，没有一个系统的把握。仔细想想，真的是这样，他们的路就是工作，谁也想进一个更好的公司，所以他们也在尽力提升着自己，可事实却是，太浮躁。 除了这些，我真的觉得在其他方面也应该好好反思一下自己。 这一个月的作息非常乱，在寒假时曾经做过打算，早睡早起，可慢慢地，睡得越来越晚，同样，起得也越来越晚。开学的前几天，坚持12点之前入睡，可慢慢地，拖到凌晨一两点钟才睡，而理所应当地，早上就难以起床，早起了也还是觉得萎靡不振。最初课程比较少，而且都集中在周二这一天，所以，除了周二，几乎每天都有机会睡个懒觉，由于这个原因，自己也经常早上起得很晚，有时甚至起床就是中午吃饭的时间了。这么一来，一上午的时光岂不是白白浪费了吗？这样的结果归咎于什么？我想，是自己的毅力问题，难以持之以恒，难以律己。 开学以来一个最不让我后悔的决定就是，健身。曾经的时候，一天没有什么活动，就坐在那学习，娱乐，一坐一玩就是一整天，自己的身体确实也难以承受得了，处在一个亚健康状态。开学之初，和好朋友一起去了学校对面的健身馆去办了一张健身年卡，几乎每天我们都去练上一个多小时，互相督促，一起锻炼。我的目标是增肌，自己真的是太瘦了，在健身房，跑上几千米后，尝试各种健身器材，锻炼胸肌等等，另外还有一套腹肌撕裂者的动作，几乎每天都这么坚持做下来。一个月的时间说长也长，说短也短，自己本身太瘦，也在努力多吃，不过现在腹肌和胸肌还没有明显的迹象。不管怎样，坚持长期练下去吧，我相信会有成果的。 另外，在待人处事方面，还是觉得自己不够稳重，现在是21岁了，也该变得成熟些了。在言谈举止方面，现在回想起这一个月自己曾经做过的事，真的有些好幼稚，好可笑。我想，尝试着去变得更稳重，考虑事情更加周全，做事更加细致，结果一定更好。 过去的一个月，我大部分时间都是在宿舍，学习啊，娱乐啊，都是宅在那里，室友也是一样。现在觉得，的确是有些懒散了，而且懒散得效率低下，作息不规律。清明回去之后，是该换一种学习环境了，找一个安静的自习室，在那里看看书，敲敲代码。学习累了，听听音乐，出去走走，望一望周围同学努力的身影，去感受一下这样的状态，告别懒散的生活方式，大胆做一番新的尝试吧。而且，是时候为自己的保研做好好的准备了，专业课知识，英语，真的挺重要。 最后，想说几句话。 为了自己的梦想和所喜欢的事而努力，这份动力是发自内心的。 一个成熟的人，有一颗强大的内心，有一种强大的毅力，做事稳重，注重细节，让自己变得更加稳重和成熟吧。 在做每一件事之前，好好想想怎样可以把这件事做得更好，好好想想自己以后会不会为自己的所作而感到后悔。 让自己变得更优秀，好好经营自己，自己所想要的，说不定会随之而来。 现在凌晨四点十九，写完之后，心中一丝畅然，晚安，世界。</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-04-04 04:21:08" itemprop="dateCreated datePublished" datetime="2015-04-04T04:21:08+08:00">2015-04-04</time>
                </span>
                <span id="/1547.html" class="post-meta-item leancloud_visitors" data-flag-title="致那逝去的三月" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>2.2k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>2 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1534.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1534.html" class="post-title-link" itemprop="url">PHP高级特性八之mysqli函数库的使用</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <h3 id="1-什么是mysqli"><a href="#1-什么是mysqli" class="headerlink" title="1.什么是mysqli"></a>1.什么是mysqli</h3>
                  <p>PHP-MySQL 函数库是 PHP 操作 MySQL 资料库最原始的扩展库，PHP-MySQLi 的 i 代表 Improvement ，相当于前者的增强版，也包含了相对进阶的功能，另外本身也增加了安全性，比如可以大幅度减少 SQL 注入等问题的发生。</p>
                  <h3 id="2-mysql与mysqli的概念相关"><a href="#2-mysql与mysqli的概念相关" class="headerlink" title="2. mysql与mysqli的概念相关"></a>2. mysql与mysqli的概念相关</h3>
                  <p>（1）mysql与mysqli都是php方面的函数集，与mysql数据库关联不大。 （2）在php5版本之前，一般是用php的mysql函数去驱动mysql数据库的，比如mysql_query()的函数，属于面向过程 （3）在php5版本以后，增加了mysqli的函数功能，某种意义上讲，它是mysql系统函数的增强版，更稳定更高效更安全，与mysql_query()对应的有mysqli_query()，属于面向对象，用对象的方式操作驱动mysql数据库</p>
                  <h3 id="3-mysql与mysqli的主要区别"><a href="#3-mysql与mysqli的主要区别" class="headerlink" title="3. mysql与mysqli的主要区别"></a>3. mysql与mysqli的主要区别</h3>
                  <p>（1）mysql是非持继连接函数，mysql每次链接都会打开一个连接的进程，所以mysqli耗费资源少一些。 （2）mysqli是永远连接函数，mysqli多次运行mysqli将使用同一连接进程,从而减少了服务器的开销。mysqli封装了诸如事务等一些高级操作，同时封装了DB操作过程中的很多可用的方法。 （3）mysqli提供了面向对象编程方式和面向过程编程方式，而mysql则只可以面向过程。 例如如下代码分别是mysqli的面向对象编程方式和面向过程方式 面向对象方式</p>
                  <figure class="highlight awk">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line"><span class="variable">$mysqli</span> = new mysqli(<span class="string">"localhost"</span>, <span class="string">"my_user"</span>, <span class="string">"my_password"</span>, <span class="string">"world"</span>);</span><br><span class="line"></span><br><span class="line"><span class="regexp">/* check connection */</span> </span><br><span class="line"><span class="keyword">if</span> (mysqli_connect_errno()) &#123;</span><br><span class="line">    printf(<span class="string">"Connect failed: %s\n"</span>, mysqli_connect_error());</span><br><span class="line">    <span class="keyword">exit</span>();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">printf(<span class="string">"Host information: %s\n"</span>, <span class="variable">$mysqli</span>-&gt;host_info);</span><br><span class="line"></span><br><span class="line"><span class="regexp">/* close connection */</span></span><br><span class="line"><span class="variable">$mysqli</span>-&gt;close();</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>面向过程方式</p>
                  <figure class="highlight awk">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line"><span class="variable">$link</span> = mysqli_connect(<span class="string">"localhost"</span>, <span class="string">"my_user"</span>, <span class="string">"my_password"</span>, <span class="string">"world"</span>);</span><br><span class="line"></span><br><span class="line"><span class="regexp">/* check connection */</span> </span><br><span class="line"><span class="keyword">if</span> (!<span class="variable">$link</span>) &#123;</span><br><span class="line">    printf(<span class="string">"Connect failed: %s\n"</span>, mysqli_connect_error());</span><br><span class="line">    <span class="keyword">exit</span>();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">printf(<span class="string">"Host information: %s\n"</span>, mysqli_get_host_info(<span class="variable">$link</span>));</span><br><span class="line"></span><br><span class="line"><span class="regexp">/* close connection */</span></span><br><span class="line">mysqli_close(<span class="variable">$link</span>);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>（4）mysqli 可以通过预处理语句来减少开销和SQL注入的风险，而mysql则做不到。 <strong>综上所述，如果大家用的是PHP5，而且mysql版本在5.0以上，希望大家以后能用mysqli的就尽量使用mqsqli，不仅高效，而且更安全，而且推荐大家使用面向对象编程方式。</strong> 在这里，我们也只介绍面向对象编程方式。</p>
                  <h2 id="函数使用"><a href="#函数使用" class="headerlink" title="函数使用"></a>函数使用</h2>
                  <h3 id="1-连接数据库并获取相关信息"><a href="#1-连接数据库并获取相关信息" class="headerlink" title="1. 连接数据库并获取相关信息"></a>1. 连接数据库并获取相关信息</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	$mysqli=@<span class="keyword">new</span> mysqli(<span class="string">"localhost"</span>, <span class="string">"root"</span>, <span class="string">""</span>, <span class="string">"mysql"</span>);</span></span><br><span class="line"><span class="php">	<span class="comment">//如果连接错误</span></span></span><br><span class="line"><span class="php">	<span class="keyword">if</span>(mysqli_connect_errno())&#123;</span></span><br><span class="line"><span class="php">		<span class="keyword">echo</span> <span class="string">"连接数据库失败："</span>.mysqli_connect_error();</span></span><br><span class="line"><span class="php">		$mysqli=<span class="keyword">null</span>;</span></span><br><span class="line"><span class="php">		<span class="keyword">exit</span>;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br><span class="line"><span class="php">	<span class="comment">//获取当前字符集</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> $mysqli-&gt;character_set_name().<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//获取客户端信息</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> $mysqli-&gt;get_client_info().<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//获取mysql主机信息</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> $mysqli-&gt;host_info.<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//获取服务器信息</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> $mysqli-&gt;server_info.<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//获取服务器版本</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> $mysqli-&gt;server_version.<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//关闭数据库连接</span></span></span><br><span class="line"><span class="php">	$mysqli-&gt;close();</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果连接成功则运行结果</p>
                  <blockquote>
                    <p>latin1 mysqlnd 5.0.10 - 20111026 - $Id: e707c415db32080b3752b232487a435ee0372157 $ localhost via TCP/IP 5.6.12-log 50612</p>
                  </blockquote>
                  <p>如果连接失败则可能结果为</p>
                  <blockquote>
                    <p>连接数据库失败：Access denied for user ‘root’@’localhost’ (using password: YES) 连接数据库失败：Unknown database ‘hello’</p>
                  </blockquote>
                  <h3 id="2-查询数据"><a href="#2-查询数据" class="headerlink" title="2.查询数据"></a>2.查询数据</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	$mysqli=@<span class="keyword">new</span> mysqli(<span class="string">"localhost"</span>, <span class="string">"root"</span>, <span class="string">""</span>, <span class="string">"design"</span>);</span></span><br><span class="line"><span class="php">	<span class="comment">//如果连接错误</span></span></span><br><span class="line"><span class="php">	<span class="keyword">if</span>(mysqli_connect_errno())&#123;</span></span><br><span class="line"><span class="php">		<span class="keyword">echo</span> <span class="string">"连接数据库失败："</span>.mysqli_connect_error();</span></span><br><span class="line"><span class="php">		$mysqli=<span class="keyword">null</span>;</span></span><br><span class="line"><span class="php">		<span class="keyword">exit</span>;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br><span class="line"><span class="php">	<span class="comment">//构造SQL语句</span></span></span><br><span class="line"><span class="php">	$query = <span class="string">"SELECT * FROM  designer order by ID LIMIT 3"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//执行SQL语句</span></span></span><br><span class="line"><span class="php">	$result = $mysqli-&gt;query($query);</span></span><br><span class="line"><span class="php">	<span class="comment">//遍历结果</span></span></span><br><span class="line"><span class="php">	<span class="keyword">while</span>($row = $result-&gt;fetch_array(MYSQLI_BOTH))&#123;</span></span><br><span class="line"><span class="php">		<span class="keyword">echo</span> <span class="string">"id"</span>.$row[<span class="string">'id'</span>].<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br><span class="line"><span class="php">	<span class="comment">//释放结果集</span></span></span><br><span class="line"><span class="php">	$result-&gt;free();</span></span><br><span class="line"><span class="php">	<span class="comment">//关闭数据库连接</span></span></span><br><span class="line"><span class="php">	$mysqli-&gt;close();</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>运行结果</p>
                  <figure class="highlight">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">id10062</span><br><span class="line">id10063</span><br><span class="line">id10064</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>在这里需要注意的是</p>
                  <figure class="highlight stylus">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="function"><span class="title">fetch_array</span><span class="params">(MYSQLI_BOTH)</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>这个方法，参数有三个，分别是 MYSQLI_BOTH，MYSQLI_NUM，MYSQLI_ASSOC。 如果参数传入了 MYSQLI_BOTH，返回数组的索引既包括数字和名称。</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">array (<span class="attribute">size</span>=26)</span><br><span class="line">  0 =&gt; string <span class="string">'10062'</span> (<span class="attribute">length</span>=5)</span><br><span class="line">  <span class="string">'id'</span> =&gt; string <span class="string">'10062'</span> (<span class="attribute">length</span>=5)</span><br><span class="line">  1 =&gt; string <span class="string">'??'</span> (<span class="attribute">length</span>=2)</span><br><span class="line">  <span class="string">'name'</span> =&gt; string <span class="string">'??'</span> (<span class="attribute">length</span>=2)</span><br><span class="line">  2 =&gt; string <span class="string">'1016903103@qq.com'</span> (<span class="attribute">length</span>=17)</span><br><span class="line">  <span class="string">'email'</span> =&gt; string <span class="string">'1016903103@qq.com'</span> (<span class="attribute">length</span>=17)</span><br><span class="line">  3 =&gt; string <span class="string">'18366119732'</span> (<span class="attribute">length</span>=11)</span><br><span class="line">  <span class="string">'phone'</span> =&gt; string <span class="string">'18366119732'</span> (<span class="attribute">length</span>=11)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果参数传入了 MYSQLI_NUM，返回数组的索引只包含数字。</p>
                  <figure class="highlight lsl">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">array (size=<span class="number">13</span>)</span><br><span class="line">  <span class="number">0</span> =&gt; <span class="type">string</span> '<span class="number">10062</span>' (length=<span class="number">5</span>)</span><br><span class="line">  <span class="number">1</span> =&gt; <span class="type">string</span> '??' (length=<span class="number">2</span>)</span><br><span class="line">  <span class="number">2</span> =&gt; <span class="type">string</span> '<span class="number">1016903103</span>@qq.com' (length=<span class="number">17</span>)</span><br><span class="line">  <span class="number">3</span> =&gt; <span class="type">string</span> '<span class="number">18366119732</span>' (length=<span class="number">11</span>)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果参数传入了 MYSQLI_BOTH，返回数组的索引只包含名称。</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">array (<span class="attribute">size</span>=13)</span><br><span class="line">  <span class="string">'id'</span> =&gt; string <span class="string">'10062'</span> (<span class="attribute">length</span>=5)</span><br><span class="line">  <span class="string">'name'</span> =&gt; string <span class="string">'??'</span> (<span class="attribute">length</span>=2)</span><br><span class="line">  <span class="string">'email'</span> =&gt; string <span class="string">'1016903103@qq.com'</span> (<span class="attribute">length</span>=17)</span><br><span class="line">  <span class="string">'phone'</span> =&gt; string <span class="string">'18366119732'</span> (<span class="attribute">length</span>=11)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>其实还有等价的方法 fetch_row()，fetch_assoc()</p>
                  <p>他们之间的关系如下</p>
                  <blockquote>
                    <p>$result-&gt;fetch_row() = mysql_fetch_row() = $result-&gt;fetch_array(MYSQLI_NUM) = mysql_fetch_array(MYSQLI_NUM) 返回索引数组</p>
                    <p>$result-&gt;fetch_assoc() = mysql_fetch_assoc() = $result-&gt;fetch_array(MYSQLI_ASSOC) = mysql_fetch_array(MYSQLI_ASSOC) 返回索引列名</p>
                  </blockquote>
                  <p>如果 fetch_array()方法什么也不传，则默认传入了 MYSQLI_BOTH</p>
                  <h3 id="3-插入数据"><a href="#3-插入数据" class="headerlink" title="3.插入数据"></a>3.插入数据</h3>
                  <figure class="highlight awk">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="variable">$mysqli</span>=@new mysqli(<span class="string">"localhost"</span>, <span class="string">"root"</span>, <span class="string">""</span>, <span class="string">"design"</span>);</span><br><span class="line">	<span class="regexp">//</span>如果连接错误</span><br><span class="line">	<span class="keyword">if</span>(mysqli_connect_errno())&#123;</span><br><span class="line">		echo <span class="string">"连接数据库失败："</span>.mysqli_connect_error();</span><br><span class="line">		<span class="variable">$mysqli</span>=null;</span><br><span class="line">		<span class="keyword">exit</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="regexp">//</span>插入数据</span><br><span class="line">	<span class="variable">$sql</span>=<span class="string">"insert into designer(name,phone) values('hello','18352682923')"</span>;</span><br><span class="line">	<span class="regexp">//</span>执行插入语句</span><br><span class="line">	<span class="variable">$result</span>=<span class="variable">$mysqli</span>-&gt;query(<span class="variable">$sql</span>);</span><br><span class="line">	<span class="regexp">//</span>如果执行错误</span><br><span class="line">	<span class="keyword">if</span>(!<span class="variable">$result</span>)&#123;</span><br><span class="line">		echo <span class="string">"SQL语句有误&lt;br&gt;"</span>;</span><br><span class="line">		echo <span class="string">"ERROR:"</span>.<span class="variable">$mysqli</span>-&gt;errno.<span class="string">"|"</span>.<span class="variable">$mysqli</span>-&gt;error;</span><br><span class="line">		<span class="keyword">exit</span>;	</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="regexp">//</span>如果插入成功，则返回影响的行数</span><br><span class="line">	echo <span class="variable">$mysqli</span>-&gt;affected_rows;</span><br><span class="line">	<span class="regexp">//</span>关闭数据库连接</span><br><span class="line">	<span class="variable">$mysqli</span>-&gt;close();</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果插入成功，那么结果则会是1，如果失败，则会报出错误。</p>
                  <h3 id="4-修改内容"><a href="#4-修改内容" class="headerlink" title="4.修改内容"></a>4.修改内容</h3>
                  <figure class="highlight awk">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="variable">$mysqli</span>=@new mysqli(<span class="string">"localhost"</span>, <span class="string">"root"</span>, <span class="string">""</span>, <span class="string">"design"</span>);</span><br><span class="line">	<span class="regexp">//</span>如果连接错误</span><br><span class="line">	<span class="keyword">if</span>(mysqli_connect_errno())&#123;</span><br><span class="line">		echo <span class="string">"连接数据库失败："</span>.mysqli_connect_error();</span><br><span class="line">		<span class="variable">$mysqli</span>=null;</span><br><span class="line">		<span class="keyword">exit</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="regexp">//</span>插入数据</span><br><span class="line">	<span class="variable">$sql</span>=<span class="string">"update designer set name = 'hello' where id = 10062"</span>;</span><br><span class="line">	<span class="regexp">//</span>执行插入语句</span><br><span class="line">	<span class="variable">$result</span>=<span class="variable">$mysqli</span>-&gt;query(<span class="variable">$sql</span>);</span><br><span class="line">	<span class="regexp">//</span>如果执行错误</span><br><span class="line">	<span class="keyword">if</span>(!<span class="variable">$result</span>)&#123;</span><br><span class="line">		echo <span class="string">"SQL语句有误&lt;br&gt;"</span>;</span><br><span class="line">		echo <span class="string">"ERROR:"</span>.<span class="variable">$mysqli</span>-&gt;errno.<span class="string">"|"</span>.<span class="variable">$mysqli</span>-&gt;error;</span><br><span class="line">		<span class="keyword">exit</span>;	</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="regexp">//</span>如果插入成功，则返回影响的行数</span><br><span class="line">	echo <span class="variable">$mysqli</span>-&gt;affected_rows;</span><br><span class="line">	<span class="regexp">//</span>关闭数据库连接</span><br><span class="line">	<span class="variable">$mysqli</span>-&gt;close();</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果修改成功，同样返回被修改的行数。</p>
                  <h3 id="5-预处理语句"><a href="#5-预处理语句" class="headerlink" title="5.预处理语句"></a>5.预处理语句</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	$mysqli = @<span class="keyword">new</span> mysqli(<span class="string">"localhost"</span>, <span class="string">"root"</span>, <span class="string">""</span>, <span class="string">"design"</span>);</span></span><br><span class="line"><span class="php">	<span class="comment">//如果连接错误</span></span></span><br><span class="line"><span class="php">	<span class="keyword">if</span>(mysqli_connect_errno())&#123;</span></span><br><span class="line"><span class="php">		<span class="keyword">echo</span> <span class="string">"连接数据库失败："</span>.mysqli_connect_error();</span></span><br><span class="line"><span class="php">		$mysqli=<span class="keyword">null</span>;</span></span><br><span class="line"><span class="php">		<span class="keyword">exit</span>;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br><span class="line"><span class="php">	<span class="comment">//准备好一条语句放到服务器中，插入语句</span></span></span><br><span class="line"><span class="php">	$sql = <span class="string">"insert into designer(name, email) values(?, ?)"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//生成预处理语句</span></span></span><br><span class="line"><span class="php">	$stmt = $mysqli-&gt;prepare($sql);</span></span><br><span class="line"><span class="php">	<span class="comment">//给占位符号每个?号传值（绑定参数） i  d  s  b，第一个参数为格式化字符，ss代表两个字符串，d代表数字</span></span></span><br><span class="line"><span class="php">	$stmt-&gt;bind_param(<span class="string">"ss"</span>, $name, $email);</span></span><br><span class="line"><span class="php">	<span class="comment">//为变量赋值</span></span></span><br><span class="line"><span class="php">	$name = <span class="string">"Mike"</span>;</span></span><br><span class="line"><span class="php">	$email = <span class="string">"mike@live.cn"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//执行</span></span></span><br><span class="line"><span class="php">	$stmt-&gt;execute();</span></span><br><span class="line"><span class="php">	<span class="comment">//为变量赋值</span></span></span><br><span class="line"><span class="php">	$name = <span class="string">"Larry"</span>;</span></span><br><span class="line"><span class="php">	$email = <span class="string">"larry@live.cn"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//执行</span></span></span><br><span class="line"><span class="php">	$stmt-&gt;execute();</span></span><br><span class="line"><span class="php">	<span class="comment">//最后输出</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> <span class="string">"最后ID"</span>.$stmt-&gt;insert_id.<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> <span class="string">"影响了"</span>.$stmt-&gt;affected_rows.<span class="string">"行&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">	<span class="comment">//关闭数据库连接</span></span></span><br><span class="line"><span class="php">	$mysqli-&gt;close();</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>通过以上的预处理语句，我们也可以实现数据插入。 那么预处理语句有什么特点呢？</p>
                  <blockquote>
                    <p>1. 效率上更高， 就是如果执行多次相同的语句，只有语句数据不同， 因为将一条语句在服务器端准备好，然后将不同的值传给服务器，再让这条语句执行。相当于编译一次，使用多次。 2. 安全上：可以防止SQL注入（? 占位）这样就可以防止非正常的变量的注入。</p>
                  </blockquote>
                  <p>所以，推荐大家使用mysqli的预处理语句的方式，不仅效率高，而且更加安全。</p>
                  <h2 id="综述-1"><a href="#综述-1" class="headerlink" title="综述"></a>综述</h2>
                  <p>以上就是对mysqli的一些方法的介绍，更加详细的内容，请查看 PHP 手册。 希望对大家有帮助！</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-30 17:04:27" itemprop="dateCreated datePublished" datetime="2015-03-30T17:04:27+08:00">2015-03-30</time>
                </span>
                <span id="/1534.html" class="post-meta-item leancloud_visitors" data-flag-title="PHP高级特性八之mysqli函数库的使用" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>5.7k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>5 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1527.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1527.html" class="post-title-link" itemprop="url">PHP高级特性七之验证码操作</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>对于PHP的图像处理来说，应用最广泛的便是验证码处理了，上一节我们学习到了PHP绘图的一些基本操作。现在我们实际运用一下，来感受一下验证码的相关应用。 在这里，我们将整个验证码写成了一个PHP类，以后我们用的时候直接调用这个类就好了。 传入的参数为验证码的宽度，高度，还有验证码的字符。</p>
                  <h2 id="验证码类"><a href="#验证码类" class="headerlink" title="验证码类"></a>验证码类</h2>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"></span><br><span class="line"><span class="php">	<span class="class"><span class="keyword">class</span> <span class="title">Code</span> </span>&#123;</span></span><br><span class="line"><span class="php">		<span class="comment">//验证码的宽度</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $width;</span></span><br><span class="line"><span class="php">		<span class="comment">//验证码的高度</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $height;</span></span><br><span class="line"><span class="php">		<span class="comment">//验证码字符的个数</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $codeNum;</span></span><br><span class="line"><span class="php">		<span class="comment">//图像资源</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $image;</span></span><br><span class="line"><span class="php">		<span class="comment">//干扰点的个数</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $disturbColorNum;</span></span><br><span class="line"><span class="php">		<span class="comment">//验证码字符内容</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $checkCode;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//构造方法，默认宽为80，高为20，字符个数为4</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">($width=<span class="number">80</span>, $height=<span class="number">20</span>, $codeNum=<span class="number">4</span>)</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="comment">//赋值成员变量</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;width=$width;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;height=$height;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;codeNum=$codeNum;</span></span><br><span class="line"><span class="php">			<span class="comment">//获得验证码字符内容</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;checkCode=<span class="keyword">$this</span>-&gt;createCheckCode();</span></span><br><span class="line"><span class="php">			<span class="comment">//设置干扰点的个数</span></span></span><br><span class="line"><span class="php">			$number=floor($width*$height/<span class="number">15</span>);</span></span><br><span class="line"><span class="php">			<span class="keyword">if</span>($number &gt; <span class="number">240</span>-$codeNum)&#123;</span></span><br><span class="line"><span class="php">				<span class="keyword">$this</span>-&gt;disturbColorNum=	<span class="number">240</span>-$codeNum;</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="php">				<span class="keyword">$this</span>-&gt;disturbColorNum=$number;</span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//通过访问该方法向浏览器中输出图像</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">showImage</span><span class="params">($fontFace=<span class="string">""</span>)</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="comment">//第一步：创建图像背景</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;createImage();</span></span><br><span class="line"><span class="php">			<span class="comment">//第二步：设置干扰元素</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;setDisturbColor();</span></span><br><span class="line"><span class="php">			<span class="comment">//第三步：向图像中随机画出文本</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;outputText($fontFace);</span></span><br><span class="line"><span class="php">			<span class="comment">//第四步：输出图像</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;outputImage();</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">			</span></span><br><span class="line"><span class="php">		<span class="comment">//通过调用该方法获取随机创建的验证码字符串</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">getCheckCode</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">return</span> <span class="keyword">$this</span>-&gt;checkCode;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//设置图像资源</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">createImage</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="comment">//创建图像资源</span></span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;image=imagecreatetruecolor(<span class="keyword">$this</span>-&gt;width, <span class="keyword">$this</span>-&gt;height);</span></span><br><span class="line"><span class="php">			<span class="comment">//随机背景色</span></span></span><br><span class="line"><span class="php">			$backColor=imagecolorallocate(<span class="keyword">$this</span>-&gt;image, rand(<span class="number">225</span>, <span class="number">255</span>), rand(<span class="number">225</span>,<span class="number">255</span>), rand(<span class="number">225</span>, <span class="number">255</span>));</span></span><br><span class="line"><span class="php">			<span class="comment">//为背景添充颜色</span></span></span><br><span class="line"><span class="php">			imagefill(<span class="keyword">$this</span>-&gt;image, <span class="number">0</span>, <span class="number">0</span>, $backColor);</span></span><br><span class="line"><span class="php">			<span class="comment">//设置边框颜色</span></span></span><br><span class="line"><span class="php">			$border=imagecolorallocate(<span class="keyword">$this</span>-&gt;image, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span></span><br><span class="line"><span class="php">			<span class="comment">//画出矩形边框</span></span></span><br><span class="line"><span class="php">			imagerectangle(<span class="keyword">$this</span>-&gt;image, <span class="number">0</span>, <span class="number">0</span>, <span class="keyword">$this</span>-&gt;width<span class="number">-1</span>, <span class="keyword">$this</span>-&gt;height<span class="number">-1</span>, $border);</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//创建干扰元素</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> <span class="function"><span class="keyword">function</span>  <span class="title">setDisturbColor</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="comment">//创建干扰的点</span></span></span><br><span class="line"><span class="php">			<span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt;<span class="keyword">$this</span>-&gt;disturbColorNum; $i++)&#123;</span></span><br><span class="line"><span class="php">				$color=imagecolorallocate(<span class="keyword">$this</span>-&gt;image, rand(<span class="number">0</span>, <span class="number">255</span>), rand(<span class="number">0</span>, <span class="number">255</span>), rand(<span class="number">0</span>, <span class="number">255</span>));</span></span><br><span class="line"><span class="php">				imagesetpixel(<span class="keyword">$this</span>-&gt;image, rand(<span class="number">1</span>, <span class="keyword">$this</span>-&gt;width<span class="number">-2</span>), rand(<span class="number">1</span>, <span class="keyword">$this</span>-&gt;height<span class="number">-2</span>), $color); </span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"><span class="php">			<span class="comment">//创建干扰的线条</span></span></span><br><span class="line"><span class="php">			<span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt;<span class="number">10</span>; $i++)&#123;</span></span><br><span class="line"><span class="php">				$color=imagecolorallocate(<span class="keyword">$this</span>-&gt;image, rand(<span class="number">200</span>, <span class="number">255</span>), rand(<span class="number">200</span>, <span class="number">255</span>), rand(<span class="number">200</span>, <span class="number">255</span>));</span></span><br><span class="line"><span class="php">				imagearc(<span class="keyword">$this</span>-&gt;image, rand(<span class="number">-10</span>, <span class="keyword">$this</span>-&gt;width), rand(<span class="number">-10</span>, <span class="keyword">$this</span>-&gt;height), rand(<span class="number">30</span>, <span class="number">300</span>), rand(<span class="number">20</span>, <span class="number">200</span>), <span class="number">55</span>, <span class="number">44</span>, $color);</span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//创建随机验证码</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">createCheckCode</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			$code=<span class="string">"23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ"</span>;</span></span><br><span class="line"><span class="php">			$string=<span class="string">''</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//从字符串中取出随机的字符</span></span></span><br><span class="line"><span class="php">			<span class="keyword">for</span>($i=<span class="number">0</span>; $i &lt; <span class="keyword">$this</span>-&gt;codeNum; $i++)&#123;</span></span><br><span class="line"><span class="php">				$char=$code&#123;rand(<span class="number">0</span>, strlen($code)<span class="number">-1</span>)&#125;;</span></span><br><span class="line"><span class="php">				$string.=$char;</span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"><span class="php">			<span class="comment">//返回字符内容</span></span></span><br><span class="line"><span class="php">			<span class="keyword">return</span> $string;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//设置验证码的字符</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">outputText</span><span class="params">($fontFace=<span class="string">""</span>)</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt;<span class="keyword">$this</span>-&gt;codeNum; $i++)&#123;</span></span><br><span class="line"><span class="php">				$fontcolor=imagecolorallocate(<span class="keyword">$this</span>-&gt;image, rand(<span class="number">0</span>, <span class="number">128</span>), rand(<span class="number">0</span>, <span class="number">128</span>), rand(<span class="number">0</span>, <span class="number">128</span>));</span></span><br><span class="line"><span class="php">				<span class="keyword">if</span>($fontFace==<span class="string">""</span>)&#123;</span></span><br><span class="line"><span class="php">					$fontsize=rand(<span class="number">3</span>, <span class="number">5</span>);</span></span><br><span class="line"><span class="php">					$x=floor(<span class="keyword">$this</span>-&gt;width/<span class="keyword">$this</span>-&gt;codeNum)*$i+<span class="number">3</span>;</span></span><br><span class="line"><span class="php">					$y=rand(<span class="number">0</span>, <span class="keyword">$this</span>-&gt;height<span class="number">-15</span>);</span></span><br><span class="line"><span class="php">					imagechar(<span class="keyword">$this</span>-&gt;image,$fontsize, $x, $y, <span class="keyword">$this</span>-&gt;checkCode&#123;$i&#125;,$fontcolor);</span></span><br><span class="line"><span class="php">				&#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="php">					$fontsize=rand(<span class="number">12</span>, <span class="number">16</span>);</span></span><br><span class="line"><span class="php">					$x=floor((<span class="keyword">$this</span>-&gt;width<span class="number">-8</span>)/<span class="keyword">$this</span>-&gt;codeNum)*$i+<span class="number">8</span>;</span></span><br><span class="line"><span class="php">					$y=rand($fontSize+<span class="number">5</span>, <span class="keyword">$this</span>-&gt;height);</span></span><br><span class="line"><span class="php">					imagettftext(<span class="keyword">$this</span>-&gt;image,$fontsize,rand(<span class="number">-30</span>, <span class="number">30</span>),$x,$y ,$fontcolor, $fontFace, <span class="keyword">$this</span>-&gt;checkCode&#123;$i&#125;);</span></span><br><span class="line"><span class="php">				&#125;</span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//输出验证码图像资源</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> <span class="function"><span class="keyword">function</span> <span class="title">outputImage</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">if</span>(imagetypes() &amp; IMG_GIF)&#123;</span></span><br><span class="line"><span class="php">				header(<span class="string">"Content-Type:image/gif"</span>);</span></span><br><span class="line"><span class="php">				imagepng(<span class="keyword">$this</span>-&gt;image);</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(imagetypes() &amp; IMG_JPG)&#123;</span></span><br><span class="line"><span class="php">				header(<span class="string">"Content-Type:image/jpeg"</span>);</span></span><br><span class="line"><span class="php">				imagepng(<span class="keyword">$this</span>-&gt;image);</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(imagetypes() &amp; IMG_PNG)&#123;</span></span><br><span class="line"><span class="php">				header(<span class="string">"Content-Type:image/png"</span>);</span></span><br><span class="line"><span class="php">				imagepng(<span class="keyword">$this</span>-&gt;image);</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(imagetypes() &amp; IMG_WBMP)&#123;</span></span><br><span class="line"><span class="php">				header(<span class="string">"Content-Type:image/vnd.wap.wbmp"</span>);</span></span><br><span class="line"><span class="php">				imagepng(<span class="keyword">$this</span>-&gt;image);</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="php">				<span class="keyword">die</span>(<span class="string">"PHP不支持图像创建"</span>);</span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		<span class="comment">//析构方法</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">__destruct</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="comment">//销毁图像资源</span></span></span><br><span class="line"><span class="php">			imagedestroy(<span class="keyword">$this</span>-&gt;image);</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>以上便是我们的验证码类的全部实现，保存文件名为 code.class.php， 下面我们来看一下怎样应用。</p>
                  <h2 id="实际应用"><a href="#实际应用" class="headerlink" title="实际应用"></a>实际应用</h2>
                  <p>我们写好了这个类之后，该怎么来调用呢？我们写一个demo如下</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	session_start();</span></span><br><span class="line"><span class="php">	<span class="keyword">include</span> <span class="string">"code.class.php"</span>;</span></span><br><span class="line"><span class="php">	$code=<span class="keyword">new</span> Code(<span class="number">80</span>, <span class="number">20</span>, <span class="number">4</span>);</span></span><br><span class="line"><span class="php">	$code-&gt;showImage();   <span class="comment">//输出到页面中供 注册或登录使用</span></span></span><br><span class="line"><span class="php">	$_SESSION[<span class="string">"code"</span>]=$code-&gt;getCheckCode();  <span class="comment">//将验证码保存到服务器中</span></span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>这段代码声明了一个code对象，然后调用 showImage 方法，显示出验证码，最后通过getCheckCode 方法，获得验证码字符串的内容，保存到了 session 全局变量中。 以上代码我们保存成 code.php 文件 之后，我们写一个表单来提交验证一下</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	session_start();</span></span><br><span class="line"><span class="php">	<span class="keyword">if</span>(@$_POST[<span class="string">"code"</span>]&amp;&amp;strtoupper($_POST[<span class="string">"code"</span>])==strtoupper($_SESSION[<span class="string">"code"</span>]))&#123;</span></span><br><span class="line"><span class="php">		<span class="keyword">echo</span> <span class="string">"ok"</span>;</span></span><br><span class="line"><span class="php">	&#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="php">		<span class="keyword">echo</span> <span class="string">"error"</span>;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">"login.php"</span> <span class="attr">method</span>=<span class="string">"post"</span>&gt;</span></span><br><span class="line">		code: <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"code"</span>&gt;</span> <span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">"code.php"</span> <span class="attr">onclick</span>=<span class="string">"this.src='code.php?'+Math.random()"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> <span class="attr">name</span>=<span class="string">"sub"</span> <span class="attr">value</span>=<span class="string">"login"</span>&gt;</span><span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>上面的代码包括了一个输入框还有验证码，验证码的 src 资源可以直接引用为 code.php 文件，这里需要注意的是，后面要加一个参数，防止因为浏览器缓存原因而导致验证码无法更换。 最后表单是提交到文件本身，所以就可以比较提交的数据和 session 全局变量之间的关系，如果相同输出 ok，如果不同输出 error 小伙伴可以验证一下！希望对大家有帮助！</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-29 14:42:05" itemprop="dateCreated datePublished" datetime="2015-03-29T14:42:05+08:00">2015-03-29</time>
                </span>
                <span id="/1527.html" class="post-meta-item leancloud_visitors" data-flag-title="PHP高级特性七之验证码操作" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>4.8k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>4 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1515.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1515.html" class="post-title-link" itemprop="url">PHP高级特性六之图像处理</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>PHP的图像处理主要有下面几个用途，一个是验证码的操作，另一个就是图像水印操作，这里我们一起来学习一下吧。</p>
                  <h2 id="图像处理基础"><a href="#图像处理基础" class="headerlink" title="图像处理基础"></a>图像处理基础</h2>
                  <h3 id="1-总体流程"><a href="#1-总体流程" class="headerlink" title="1.总体流程"></a>1.总体流程</h3>
                  <p>首先，我们必须先了解PHP图像处理的基本函数的用法。总体来说分为以下四个步骤</p>
                  <h4 id="（1）创建画布，创建资源类型，指定-高度-宽度"><a href="#（1）创建画布，创建资源类型，指定-高度-宽度" class="headerlink" title="（1）创建画布，创建资源类型，指定 高度 宽度"></a>（1）创建画布，创建资源类型，指定 高度 宽度</h4>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">resource imagecreate ( int x_size, int y_size )</span><br><span class="line">resource imagecreatetruecolor ( int x_size, int y_size )</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>imagecreate() 返回一个图像标识符，代表了一幅大小为 x_size 和 y_size 的空白图像。不过推荐使用 imagecreatetruecolor()，这个是新建一个真彩色图像。</p>
                  <h4 id="（2）绘制图像"><a href="#（2）绘制图像" class="headerlink" title="（2）绘制图像"></a>（2）绘制图像</h4>
                  <p>制定各种颜色，矩形， 圆， 点， 线段， 扇形， 画字（字符， 字符串， freetype），每一个形状和字符绘制对应一个函数，这部分我们后面详细介绍。</p>
                  <h4 id="（3）输出图像-保存处理好的图像"><a href="#（3）输出图像-保存处理好的图像" class="headerlink" title="（3）输出图像/保存处理好的图像"></a>（3）输出图像/保存处理好的图像</h4>
                  <figure class="highlight abnf">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">imagegif()<span class="comment">;</span></span><br><span class="line">imagejpeg()<span class="comment">;</span></span><br><span class="line">imagepng()<span class="comment">;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>例如，imagegif() 则将其保存为gif格式的图像。 <strong>bool imagegif ( resource image [, string filename] )</strong></p>
                  <blockquote>
                    <p>imagegif() 从 image 图像以 filename 为文件名创建一个 GIF 图像。image 参数是 imagecreatetruecolor() 函数的返回值。 filename 参数为可选，如果省略，则原始图像流将被直接输出。通过 header() 发送 Content-type: image/gif 可以使 PHP 脚本直接输出 GIF 图像。</p>
                  </blockquote>
                  <h4 id="（4）释放资源"><a href="#（4）释放资源" class="headerlink" title="（4）释放资源"></a>（4）释放资源</h4>
                  <figure class="highlight arcade">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">imagedestroy(<span class="symbol">$img</span>);</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>所以，我们创建图像的一般流程用代码可以总结如下</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	<span class="comment">//创建图片资源</span></span></span><br><span class="line"><span class="php">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span></span><br><span class="line"><span class="php">	<span class="comment">//绘制图形</span></span></span><br><span class="line"><span class="php">	$red = imagecolorallocate($img, <span class="number">0xFF</span>, <span class="number">0</span>, <span class="number">0</span>);</span></span><br><span class="line"><span class="php">	imagechar($img, <span class="number">5</span>, <span class="number">100</span>, <span class="number">100</span>, <span class="string">"A"</span>, $red);</span></span><br><span class="line"><span class="php">	<span class="comment">//输出图像</span></span></span><br><span class="line"><span class="php">	header(<span class="string">"Content-Type:image/gif"</span>);</span></span><br><span class="line"><span class="php">	imagegif($img);</span></span><br><span class="line"><span class="php">	<span class="comment">//释放资源</span></span></span><br><span class="line"><span class="php">	imagedestroy($img);</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>输出的结果如下，它直接在浏览器中显示如下，背景默认为黑色。 <img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328153220-e1427528691389.jpg" alt="20150328153220"> 如果我们不加header，那么则会显示字符乱码，所以一定要记得下面这句话。</p>
                  <figure class="highlight abnf">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">header(<span class="string">"Content-Type:image/gif"</span>)<span class="comment">;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="2-设置色彩"><a href="#2-设置色彩" class="headerlink" title="2.设置色彩"></a>2.设置色彩</h3>
                  <p>我们主要用到下面这个函数 <strong>int imagecolorallocate ( resource image, int red, int green, int blue )</strong> imagecolorallocate() 返回一个标识符，代表了由给定的 RGB 成分组成的颜色。image 参数是 imagecreatetruecolor() 函数的返回值。red，green 和 blue 分别是所需要的颜色的红，绿，蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xFF。imagecolorallocate() 必须被调用以创建每一种用在 image 所代表的图像中的颜色。 例如下面的例子</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="comment">//十进制方式</span></span><br><span class="line">	$red = imagecolorallocate($img, <span class="number">0xFF</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	$white = imagecolorallocate($im, <span class="number">255</span>, <span class="number">255</span>, <span class="number">255</span>);</span><br><span class="line">	$black = imagecolorallocate($im, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	<span class="comment">// 十六进制方式</span></span><br><span class="line">	$gray = imagecolorallocate($img, <span class="number">0xEE</span>, <span class="number">0xEE</span>, <span class="number">0xEE</span>);</span><br><span class="line">	$white = imagecolorallocate($im, <span class="number">0xFF</span>, <span class="number">0xFF</span>, <span class="number">0xFF</span>);</span><br><span class="line">	$black = imagecolorallocate($im, <span class="number">0x00</span>, <span class="number">0x00</span>, <span class="number">0x00</span>);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="3-区域填充色彩"><a href="#3-区域填充色彩" class="headerlink" title="3.区域填充色彩"></a>3.区域填充色彩</h3>
                  <p><strong>bool imagefill ( resource image, int x, int y, int color )</strong> imagefill() 在 image 图像的坐标 x，y（图像左上角为 0, 0）处用 color 颜色执行区域填充（即与 x, y 点颜色相同且相邻的点都会被填充）。 好，让我们尝试一下填充背景色吧</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	<span class="comment">//创建图片资源</span></span></span><br><span class="line"><span class="php">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span></span><br><span class="line"><span class="php">	<span class="comment">//绘制图形</span></span></span><br><span class="line"><span class="php">	$red = imagecolorallocate($img, <span class="number">0xFF</span>, <span class="number">0</span>, <span class="number">0</span>);</span></span><br><span class="line"><span class="php">	imagefill($img,<span class="number">0</span>,<span class="number">0</span>,$red);</span></span><br><span class="line"><span class="php">	<span class="comment">//输出图像</span></span></span><br><span class="line"><span class="php">	header(<span class="string">"Content-Type:image/gif"</span>);</span></span><br><span class="line"><span class="php">	imagegif($img);</span></span><br><span class="line"><span class="php">	<span class="comment">//释放资源</span></span></span><br><span class="line"><span class="php">	imagedestroy($img);</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>运行结果如下，背景被填充为了红色。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/QQ截图20150328154707.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/QQ截图20150328154707.jpg" alt="20150328154707"></a></p>
                  <h3 id="4-画各种元素"><a href="#4-画各种元素" class="headerlink" title="4.画各种元素"></a>4.画各种元素</h3>
                  <h4 id="（1）画空心矩形"><a href="#（1）画空心矩形" class="headerlink" title="（1）画空心矩形"></a>（1）画空心矩形</h4>
                  <p><strong>bool imagerectangle ( resource image, int x1, int y1, int x2, int y2, int col )</strong> imagerectangle() 用 col 颜色在 image 图像中画一个矩形，其左上角坐标为 x1, y1，右下角坐标为 x2, y2。图像的左上角坐标为 0, 0。</p>
                  <h4 id="（2）画填充矩形"><a href="#（2）画填充矩形" class="headerlink" title="（2）画填充矩形"></a>（2）画填充矩形</h4>
                  <p> <strong>bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color )</strong> imagefilledrectangle() 在 image 图像中画一个用 color 颜色填充了的矩形，其左上角坐标为 x1，y1，右下角坐标为 x2，y2。0, 0 是图像的最左上角。</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="comment">//创建图片资源</span></span><br><span class="line">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span><br><span class="line">	<span class="comment">//声明颜色</span></span><br><span class="line">	$red=imagecolorallocate($img, <span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	$yellow=imagecolorallocate($img, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$green=imagecolorallocate($img, <span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$blue=imagecolorallocate($img, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>);</span><br><span class="line">	<span class="comment">//填充背景</span></span><br><span class="line">	imagefill($img,<span class="number">0</span>,<span class="number">0</span>,$yellow);</span><br><span class="line">	<span class="comment">//画一个矩形并填充</span></span><br><span class="line">	imagefilledrectangle($img, <span class="number">10</span>, <span class="number">10</span>, <span class="number">80</span>, <span class="number">80</span>, $green);</span><br><span class="line">	<span class="comment">//画一个矩形</span></span><br><span class="line">	imagerectangle($img, <span class="number">90</span>, <span class="number">10</span>, <span class="number">190</span>, <span class="number">80</span>, $green);</span><br><span class="line">	<span class="comment">//输出图像</span></span><br><span class="line">	header(<span class="string">"Content-Type:image/gif"</span>);</span><br><span class="line">	imagegif($img);</span><br><span class="line">	<span class="comment">//释放资源</span></span><br><span class="line">	imagedestroy($img);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328155313.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328155313.jpg" alt="20150328155313"></a></p>
                  <h4 id="（3）画一条线段"><a href="#（3）画一条线段" class="headerlink" title="（3）画一条线段"></a>（3）画一条线段</h4>
                  <p><strong>bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )</strong> imageline() 用 color 颜色在图像 image 中从坐标 x1，y1 到 x2，y2（图像左上角为 0, 0）画一条线段。</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="comment">//创建图片资源</span></span><br><span class="line">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span><br><span class="line">	<span class="comment">//声明颜色</span></span><br><span class="line">	$red=imagecolorallocate($img, <span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	$yellow=imagecolorallocate($img, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$green=imagecolorallocate($img, <span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$blue=imagecolorallocate($img, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>);</span><br><span class="line">	<span class="comment">//填充背景</span></span><br><span class="line">	imagefill($img,<span class="number">0</span>,<span class="number">0</span>,$yellow);</span><br><span class="line">	<span class="comment">//线段</span></span><br><span class="line">	imageline($img,<span class="number">0</span>, <span class="number">0</span>, <span class="number">200</span>, <span class="number">200</span> ,$blue);</span><br><span class="line">	imageline($img,<span class="number">200</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">200</span>, $blue);</span><br><span class="line">	<span class="comment">//输出图像</span></span><br><span class="line">	header(<span class="string">"Content-Type:image/gif"</span>);</span><br><span class="line">	imagegif($img);</span><br><span class="line">	<span class="comment">//释放资源</span></span><br><span class="line">	imagedestroy($img);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328155846.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328155846.jpg" alt="20150328155846"></a></p>
                  <h4 id="（4）画点"><a href="#（4）画点" class="headerlink" title="（4）画点"></a>（4）画点</h4>
                  <p><strong>bool imagesetpixel ( resource image, int x, int y, int color )</strong> imagesetpixel() 在 image 图像中用 color 颜色在 x，y 坐标（图像左上角为 0，0）上画一个点。</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="comment">//创建图片资源</span></span><br><span class="line">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span><br><span class="line">	<span class="comment">//声明颜色</span></span><br><span class="line">	$red=imagecolorallocate($img, <span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	$yellow=imagecolorallocate($img, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$green=imagecolorallocate($img, <span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$blue=imagecolorallocate($img, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>);</span><br><span class="line">	<span class="comment">//填充背景</span></span><br><span class="line">	imagefill($img,<span class="number">0</span>,<span class="number">0</span>,$yellow);</span><br><span class="line">	<span class="comment">//点</span></span><br><span class="line">	imagesetpixel($img,<span class="number">50</span>, <span class="number">50</span> ,$red);</span><br><span class="line">	imagesetpixel($img,<span class="number">55</span>, <span class="number">50</span> ,$red);</span><br><span class="line">	imagesetpixel($img,<span class="number">59</span>, <span class="number">50</span> ,$red);</span><br><span class="line">	imagesetpixel($img,<span class="number">64</span>, <span class="number">50</span> ,$red);</span><br><span class="line">	imagesetpixel($img,<span class="number">72</span>, <span class="number">50</span> ,$red);</span><br><span class="line">	<span class="comment">//输出图像</span></span><br><span class="line">	header(<span class="string">"Content-Type:image/gif"</span>);</span><br><span class="line">	imagegif($img);</span><br><span class="line">	<span class="comment">//释放资源</span></span><br><span class="line">	imagedestroy($img);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328160304.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328160304.jpg" alt="20150328160304"></a></p>
                  <h4 id="（5）画空心圆"><a href="#（5）画空心圆" class="headerlink" title="（5）画空心圆"></a>（5）画空心圆</h4>
                  <p><strong>bool imageellipse ( resource image, int cx, int cy, int w, int h, int color )</strong> imageellipse() 在 image 所代表的图像中画一个中心为 cx，cy（图像左上角为 0, 0）的椭圆。w 和 h 分别指定了椭圆的宽度和高度，椭圆的颜色由 color 指定。</p>
                  <h4 id="（6）画实心圆"><a href="#（6）画实心圆" class="headerlink" title="（6）画实心圆"></a>（6）画实心圆</h4>
                  <p><strong>bool imagefilledellipse ( resource image, int cx, int cy, int w, int h, int color )</strong> imagefilledellipse() 在 image 所代表的图像中以 cx，cy（图像左上角为 0, 0）为中心画一个椭圆。w 和 h 分别指定了椭圆的宽和高。椭圆用 color 颜色填充。如果成功则返回 TRUE，失败则返回 FALSE。</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="comment">//创建图片资源</span></span><br><span class="line">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span><br><span class="line">	<span class="comment">//声明颜色</span></span><br><span class="line">	$red=imagecolorallocate($img, <span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	$yellow=imagecolorallocate($img, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$green=imagecolorallocate($img, <span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$blue=imagecolorallocate($img, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>);</span><br><span class="line">	<span class="comment">//填充背景</span></span><br><span class="line">	imagefill($img,<span class="number">0</span>,<span class="number">0</span>,$yellow);</span><br><span class="line">	<span class="comment">//圆</span></span><br><span class="line">	imageellipse($img, <span class="number">100</span>, <span class="number">100</span>, <span class="number">100</span>, <span class="number">100</span>,$green);</span><br><span class="line">	<span class="comment">//实心圆</span></span><br><span class="line">	imagefilledellipse($img, <span class="number">100</span>, <span class="number">100</span>, <span class="number">10</span>, <span class="number">10</span>,$blue);</span><br><span class="line">	<span class="comment">//输出图像</span></span><br><span class="line">	header(<span class="string">"Content-Type:image/gif"</span>);</span><br><span class="line">	imagegif($img);</span><br><span class="line">	<span class="comment">//释放资源</span></span><br><span class="line">	imagedestroy($img);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328161138.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328161138.jpg" alt="20150328161138"></a></p>
                  <h4 id="（7）水平画一个字符"><a href="#（7）水平画一个字符" class="headerlink" title="（7）水平画一个字符"></a>（7）水平画一个字符</h4>
                  <p><strong>bool imagechar ( resource image, int font, int x, int y, string c, int color )</strong> imagechar() 将字符串 c 的第一个字符画在 image 指定的图像中，其左上角位于 x，y（图像左上角为 0, 0），颜色为 color。如果 font 是 1，2，3，4 或 5，则使用内置的字体（更大的数字对应于更大的字体）。 <strong>bool imagestring ( resource image, int font, int x, int y, string s, int col )</strong> imagestring() 用 col 颜色将字符串 s 画到 image 所代表的图像的 x，y 坐标处（这是字符串左上角坐标，整幅图像的左上角为 0，0）。如果 font 是 1，2，3，4 或 5，则使用内置字体。</p>
                  <h4 id="（8）竖直画一个字符"><a href="#（8）竖直画一个字符" class="headerlink" title="（8）竖直画一个字符"></a>（8）竖直画一个字符</h4>
                  <p><strong>bool imagecharup ( resource image, int font, int x, int y, string c, int color )</strong> imagecharup() 将字符 c 垂直地画在 image 指定的图像上，位于 x，y（图像左上角为 0, 0），颜色为 color。如果 font 为 1，2，3，4 或 5，则使用内置的字体。 <strong>bool imagestringup ( resource image, int font, int x, int y, string s, int col )</strong> imagestring() 用 col 颜色将字符串 s 垂直地画到 image 所代表的图像的 x, y 座标处（图像的左上角为 0, 0）。如果 font 是 1，2，3，4 或 5，则使用内置字体。</p>
                  <h4 id="（9）带字体写入字符"><a href="#（9）带字体写入字符" class="headerlink" title="（9）带字体写入字符"></a>（9）带字体写入字符</h4>
                  <p><strong>array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )</strong></p>
                  <blockquote>
                    <p>image：图像资源。见 imagecreatetruecolor()。 size： 字体大小。根据 GD 版本不同，应该以像素大小指定（GD1）或点大小（GD2）。 angle： 角度制表示的角度，0 度为从左向右读的文本。更高数值表示逆时针旋转。例如 90 度表示从下向上读的文本。 x： 由 x，y 所表示的坐标定义了第一个字符的基本点（大概是字符的左下角）。这和 imagestring() 不同，其 x，y 定义了第一个字符的左上角。例如 “top left” 为 0, 0。 y： Y 坐标。它设定了字体基线的位置，不是字符的最底端。 color： 颜色索引。使用负的颜色索引值具有关闭防锯齿的效果。见 imagecolorallocate()。 fontfile： 是想要使用的 TrueType 字体的路径。 text： 文本字符串。</p>
                  </blockquote>
                  <p>imagettftext() 返回一个含有 8 个单元的数组表示了文本外框的四个角，顺序为坐下角，右下角，右上角，左上角。这些点是相对于文本的而和角度无关，因此“左上角”指的是以水平方向看文字时其左上角。</p>
                  <figure class="highlight lsl">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	<span class="comment">//创建图片资源</span></span><br><span class="line">	$img = imagecreatetruecolor( <span class="number">200</span>, <span class="number">200</span>);</span><br><span class="line">	<span class="comment">//声明颜色</span></span><br><span class="line">	$red=imagecolorallocate($img, <span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">	$yellow=imagecolorallocate($img, <span class="number">255</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$green=imagecolorallocate($img, <span class="number">0</span>, <span class="number">255</span>, <span class="number">0</span>);</span><br><span class="line">	$blue=imagecolorallocate($img, <span class="number">0</span>, <span class="number">0</span>, <span class="number">255</span>);</span><br><span class="line">	$navy=imagecolorallocate($img, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0x80</span>);</span><br><span class="line">	<span class="comment">//填充背景</span></span><br><span class="line">	imagefill($img,<span class="number">0</span>,<span class="number">0</span>,$yellow);</span><br><span class="line">	<span class="comment">//画字符</span></span><br><span class="line">	imagechar($img, <span class="number">2</span>, <span class="number">100</span>, <span class="number">100</span>, <span class="string">"A"</span>, $red);</span><br><span class="line">	imagechar($img, <span class="number">5</span>, <span class="number">120</span>, <span class="number">120</span>, <span class="string">"B"</span>, $red);</span><br><span class="line">	imagecharup($img, <span class="number">4</span>, <span class="number">60</span>, <span class="number">60</span>, <span class="string">"C"</span>, $red);</span><br><span class="line">	imagecharup($img, <span class="number">5</span>, <span class="number">80</span>, <span class="number">80</span>, <span class="string">"D"</span>, $red);</span><br><span class="line">	imagestring($img, <span class="number">3</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="string">"Hello"</span>, $navy);</span><br><span class="line">	imagestringup($img, <span class="number">3</span>, <span class="number">10</span>, <span class="number">80</span>, <span class="string">"Hello"</span>, $navy);</span><br><span class="line">	imagettftext($img, <span class="number">25</span>, <span class="number">60</span>, <span class="number">150</span>, <span class="number">150</span>, $blue, <span class="string">"simkai.ttf"</span>, <span class="string">"Hello"</span>);</span><br><span class="line">	imagettftext($img, <span class="number">12</span>, <span class="number">-60</span>, <span class="number">50</span>, <span class="number">150</span>, $green, <span class="string">"simli.ttf"</span>, <span class="string">"Nihao"</span>);</span><br><span class="line">	<span class="comment">//输出图像</span></span><br><span class="line">	header(<span class="string">"Content-Type:image/gif"</span>);</span><br><span class="line">	imagegif($img);</span><br><span class="line">	<span class="comment">//释放资源</span></span><br><span class="line">	imagedestroy($img);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328163147.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150328163147.jpg" alt="20150328163147"></a></p>
                  <h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2>
                  <p>以上我们总结了PHP图像绘图的相关函数的使用，在后面我们将应用于实际，比如验证码和图像水印操作中。 希望对大家有帮助！</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-28 16:34:50" itemprop="dateCreated datePublished" datetime="2015-03-28T16:34:50+08:00">2015-03-28</time>
                </span>
                <span id="/1515.html" class="post-meta-item leancloud_visitors" data-flag-title="PHP高级特性六之图像处理" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>6.8k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>6 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1491.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> HTML <i class="label-arrow"></i>
                  </a>
                  <a href="/1491.html" class="post-title-link" itemprop="url">使用CSS3自定义网页字体的方法</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>CSS3已经变得非常流行，原本的CSS不支持自定义字体，但是传说中的CSS3基本上什么都可以，那么CSS3中可不可以自定义英文字体呢？这里我们就一起来感受一下。</p>
                  <h2 id="语法规则"><a href="#语法规则" class="headerlink" title="语法规则"></a><strong>语法规则</strong></h2>
                  <figure class="highlight scss">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">@font-face</span> &#123;</span><br><span class="line"></span><br><span class="line">　　<span class="attribute">font-family</span>: 自定义的字体名称;</span><br><span class="line"></span><br><span class="line">　　<span class="attribute">src</span>: 自定义的字体的存放路径;</span><br><span class="line"></span><br><span class="line">　　<span class="attribute">font-weight</span>: normal;是否为粗体</span><br><span class="line"></span><br><span class="line">　　<span class="attribute">font-style</span>: normal;定义字体样式，如斜体</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="取值说明"><a href="#取值说明" class="headerlink" title="取值说明"></a><strong>取值说明</strong></h2>
                  <h3 id="font-famliy"><a href="#font-famliy" class="headerlink" title="font-famliy"></a>font-famliy</h3>
                  <p>此值指的就是你自定义的字体名称，最好是使用你下载的默认字体，他将被引用到你的Web元素中的font-family。如“font-family:”YourWebFontName”;”</p>
                  <h3 id="source"><a href="#source" class="headerlink" title="source"></a>source</h3>
                  <p>此值指的是你自定义的字体的存放路径，可以是相对路径也可以是绝路径;</p>
                  <h3 id="format"><a href="#format" class="headerlink" title="format"></a>format</h3>
                  <p>此值指的是你自定义的字体的格式，主要用来帮助浏览器识别，其值主要有以下几种类型：truetype,opentype,truetype-aat,embedded-opentype,avg等</p>
                  <h3 id="weight和style"><a href="#weight和style" class="headerlink" title="weight和style"></a>weight和style</h3>
                  <p>这两个值大家一定很熟悉，weight定义字体是否为粗体，style主要定义字体样式，如斜体</p>
                  <h2 id="各个浏览器需要字体的格式"><a href="#各个浏览器需要字体的格式" class="headerlink" title="各个浏览器需要字体的格式"></a><strong>各个浏览器需要字体的格式</strong></h2>
                  <h3 id="TureTpe-ttf"><a href="#TureTpe-ttf" class="headerlink" title="TureTpe(.ttf)"></a>TureTpe(.ttf)</h3>
                  <p>.ttf字体是Windows和Mac的最常见的字体，是一种RAW格式，因此他不为网站优化,支持这种字体的浏览器有 IE9+,Firefox3.5+,Chrome4+,Safari3+,Opera10+,iOS Mobile Safari4.2+</p>
                  <h3 id="OpenType-otf"><a href="#OpenType-otf" class="headerlink" title="OpenType(.otf)"></a>OpenType(.otf)</h3>
                  <p>.otf字体被认为是一种原始的字体格式，其内置在TureType的基础上，所以也提供了更多的功能,支持这种字体的浏览器有 Firefox3.5+,Chrome4.0+,Safari3.1+,Opera10.0+,iOS Mobile Safari4.2+</p>
                  <h3 id="Web-Open-Font-Format-woff"><a href="#Web-Open-Font-Format-woff" class="headerlink" title="Web Open Font Format(.woff)"></a>Web Open Font Format(.woff)</h3>
                  <p>.woff字体是Web字体中最佳格式，他是一个开放的TrueType/OpenType的压缩版本，同时也支持元数据包的分离,支持这种字体的浏览器有 IE9+,Firefox3.5+,Chrome6+,Safari3.6+,Opera11.1+</p>
                  <h3 id="Embedded-Open-Type-eot"><a href="#Embedded-Open-Type-eot" class="headerlink" title="Embedded Open Type(.eot)"></a>Embedded Open Type(.eot)</h3>
                  <p>.eot字体是IE专用字体，可以从TrueType创建此格式字体,支持这种字体的浏览器有 IE4+</p>
                  <h3 id="SVG-svg"><a href="#SVG-svg" class="headerlink" title="SVG(.svg)"></a>SVG(.svg)</h3>
                  <p>.svg字体是基于SVG字体渲染的一种格式,支持这种字体的浏览器有 Chrome4+,Safari3.1+,Opera10.0+,iOS Mobile Safari3.2+ 所以，@font-face中我们至少需要.woff,.eot两种格式字体，甚至还需要.svg等字体达到更多种浏览版本的支持。</p>
                  <h2 id="综合写法"><a href="#综合写法" class="headerlink" title="综合写法"></a><strong>综合写法</strong></h2>
                  <figure class="highlight css">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"> <span class="keyword">@font-face</span> &#123;</span><br><span class="line">    <span class="attribute">font-family</span>: <span class="string">'YourWebFontName'</span>;</span><br><span class="line">    <span class="comment">/* IE9 Compat Modes */</span></span><br><span class="line">    <span class="attribute">src</span>: <span class="built_in">url</span>(<span class="string">'YourWebFontName.eot'</span>);</span><br><span class="line">    <span class="comment">/* IE6-IE8 */</span></span><br><span class="line">    <span class="attribute">src</span>: <span class="built_in">url</span>(<span class="string">'YourWebFontName.eot?#iefix'</span>) <span class="built_in">format</span>(<span class="string">'embedded-opentype'</span>), </span><br><span class="line">        <span class="comment">/* Modern Browsers */</span></span><br><span class="line">        <span class="built_in">url</span>(<span class="string">'YourWebFontName.woff'</span>) <span class="built_in">format</span>(<span class="string">'woff'</span>), </span><br><span class="line">        <span class="comment">/* Safari, Android, iOS */</span></span><br><span class="line">        <span class="built_in">url</span>(<span class="string">'YourWebFontName.ttf'</span>)  <span class="built_in">format</span>(<span class="string">'truetype'</span>), </span><br><span class="line">        <span class="comment">/* Legacy iOS */</span></span><br><span class="line">        <span class="built_in">url</span>(<span class="string">'YourWebFontName.svg#YourWebFontName'</span>) <span class="built_in">format</span>(<span class="string">'svg'</span>); </span><br><span class="line">&#125;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="获取字体"><a href="#获取字体" class="headerlink" title="获取字体"></a>获取字体</h2>
                  <p>在这里介绍一个网站，叫做 <a href="http://www.fontsquirrel.com/tools/webfont-generator" target="_blank" rel="noopener">fontsquirrel</a></p>
                  <p>在这里，你可以通过上传你的字体，来获取上面四种格式的字体文件。</p>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327005358.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327005358.jpg" alt="20150327005358"></a></p>
                  <p>我们点击按钮 UPLOAD FONTS，选择本地的字体文件，然后网站就会为我们生成上述格式的字体文件，勾选 Agreement，然后直接点击下载即可，DOWNLOAD YOUR KIT。</p>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327005550.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327005550.jpg" alt="20150327005550"></a></p>
                  <p>比如我上传的字体名叫做 FuturaICG-Light，那么下载之后的文件目录就如下</p>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327010127.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327010127.jpg" alt="20150327010127"></a></p>
                  <p>其中，这个目录下给我们生成了一个demo，可以用浏览器打开 html 后缀的文件，预览一下 demo 是怎么写的。</p>
                  <h2 id="应用字体"><a href="#应用字体" class="headerlink" title="应用字体"></a>应用字体</h2>
                  <p>如果我们要用，就把五个字体文件复制一下，复制到项目目录里。</p>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327010641.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327010641.jpg" alt="20150327010641"></a></p>
                  <p>然后在样式表css中加入如下代码即可生效啦，这个代码在 demo 的 stylesheet 文件中，我们直接复制即可，比如我的便是</p>
                  <figure class="highlight css">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">@font-face</span> &#123;</span><br><span class="line">    <span class="attribute">font-family</span>: <span class="string">'futuraicg_lightregular'</span>;</span><br><span class="line">    <span class="attribute">src</span>: <span class="built_in">url</span>(<span class="string">'FuturaICG-Light-webfont.eot'</span>);</span><br><span class="line">    <span class="attribute">src</span>: <span class="built_in">url</span>(<span class="string">'FuturaICG-Light-webfont.eot?#iefix'</span>) <span class="built_in">format</span>(<span class="string">'embedded-opentype'</span>),</span><br><span class="line">         <span class="built_in">url</span>(<span class="string">'FuturaICG-Light-webfont.woff2'</span>) <span class="built_in">format</span>(<span class="string">'woff2'</span>),</span><br><span class="line">         <span class="built_in">url</span>(<span class="string">'FuturaICG-Light-webfont.woff'</span>) <span class="built_in">format</span>(<span class="string">'woff'</span>),</span><br><span class="line">         <span class="built_in">url</span>(<span class="string">'FuturaICG-Light-webfont.ttf'</span>) <span class="built_in">format</span>(<span class="string">'truetype'</span>),</span><br><span class="line">         <span class="built_in">url</span>(<span class="string">'FuturaICG-Light-webfont.svg#futuraicg_lightregular'</span>) <span class="built_in">format</span>(<span class="string">'svg'</span>);</span><br><span class="line">    <span class="attribute">font-weight</span>: normal;</span><br><span class="line">    <span class="attribute">font-style</span>: normal;</span><br><span class="line">&#125;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>在这里要注意路径问题，如果 css 在字体的上级目录，那么就要在前面加上字体文件夹的名称，我想大家都能理解。 刷新一下页面，我们可以发现页面的字体效果就已经生效啦。 如果有不生效的地方，很可能是 CSS 表中设置了 html 或者 body 的 font-family 样式，在这里我们只需要把它们去掉即可。如图所示，把改行删掉即可。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327011119.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327011119.jpg" alt="20150327011119"></a></p>
                  <p>这时，如果还不行，请检查路径设置。 以上就是我们用 CSS3 来自定义网页字体的方法，希望对大家有帮助。</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-27 01:13:20" itemprop="dateCreated datePublished" datetime="2015-03-27T01:13:20+08:00">2015-03-27</time>
                </span>
                <span id="/1491.html" class="post-meta-item leancloud_visitors" data-flag-title="使用CSS3自定义网页字体的方法" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>2.5k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>2 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1485.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> Other <i class="label-arrow"></i>
                  </a>
                  <a href="/1485.html" class="post-title-link" itemprop="url">Mysql数据库无法远程连接的解决方法</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <p>在远程主机上，我开启了mysql 服务，用 phpmyadmin 可以打开，比如说用户名为 root，密码为 123456。不过用 Mysql 客户端远程连接时却报了错误，比如 Mysql-Front 报了如下错误。 Access denied for user ‘root’@’121.42.8.33’(using password:YES) <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327004005.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150327004005.jpg" alt="20150327004005"></a> 比较奇怪，phpmyadmin 可以正常访问，而 Mysql-Front 为什么无法连接呢？可能的原因，应该就是 IP 限制了，phpmyadmin在连接时使用的是localhost，而我们访问页面才使用的远程主机的 IP，而 Mysql-Front 连接的是远程主机。 解决方法如下， 首先修改mysql的配置文件,my.cnf,将</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">#bind-address = <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>这一行注释掉,要不然它永远限制了只能本机连接 然后我们需要新建一个用户，然后授予所有 IP 可以访问的权限就好啦。 在下面的 sql 语句中，username 即为用户名，password 为你要设置的密码。</p>
                  <figure class="highlight sql">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">USER</span> <span class="string">'username'</span>@<span class="string">'localhost'</span> <span class="keyword">IDENTIFIED</span> <span class="keyword">BY</span> <span class="string">'password'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">GRANT</span> <span class="keyword">ALL</span> <span class="keyword">PRIVILEGES</span> <span class="keyword">ON</span> *.* <span class="keyword">TO</span> <span class="string">'username'</span>@<span class="string">'localhost'</span> <span class="keyword">WITH</span> <span class="keyword">GRANT</span> <span class="keyword">OPTION</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">USER</span> <span class="string">'username'</span>@<span class="string">'%'</span> <span class="keyword">IDENTIFIED</span> <span class="keyword">BY</span> <span class="string">'password'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">GRANT</span> <span class="keyword">ALL</span> <span class="keyword">PRIVILEGES</span> <span class="keyword">ON</span> *.* <span class="keyword">TO</span> <span class="string">'username'</span>@<span class="string">'%'</span> <span class="keyword">WITH</span> <span class="keyword">GRANT</span> <span class="keyword">OPTION</span>;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>通过执行以上语句，便创建了一个用户名为 username，密码为 password 的新账户，再用新账号登录，就可以连接成功啦。</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-27 00:43:10" itemprop="dateCreated datePublished" datetime="2015-03-27T00:43:10+08:00">2015-03-27</time>
                </span>
                <span id="/1485.html" class="post-meta-item leancloud_visitors" data-flag-title="Mysql数据库无法远程连接的解决方法" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>722</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1479.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1479.html" class="post-title-link" itemprop="url">PHP高级特性学习总结</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <p>搞WEB开发，PHP后台当然少不了，PHP的高级用法虽然不一定用到，但是作为WEB开发人员，是必须要了解的。在这里，博主把自己学习的一些高级特性总结如下，希望对大家有帮助。</p>
                  <h2 id="PHP高级特性总结"><a href="#PHP高级特性总结" class="headerlink" title="PHP高级特性总结"></a>PHP高级特性总结</h2>
                  <p><a href="http://cuiqingcai.com/1186.html">1. PHP高级特性一之正则表达式用法</a> 2. <a href="http://cuiqingcai.com/1229.html">PHP高级特性二之文件处理</a> 3. <a href="http://cuiqingcai.com/1290.html">PHP高级特性三之文件上传和下载</a> 4. <a href="http://cuiqingcai.com/1470.html">PHP高级特性四之SMTP邮件发送</a> 5. <a href="http://cuiqingcai.com/1473.html">PHP高级特性五之时间处理</a> 6. <a href="http://cuiqingcai.com/1515.html">PHP高级特性六之图像处理</a> 7. <a href="http://cuiqingcai.com/1527.html">PHP高级特性七之验证码操作</a> 随着学习的进行，会不断更新，希望对大家有帮助！</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-19 14:44:03" itemprop="dateCreated datePublished" datetime="2015-03-19T14:44:03+08:00">2015-03-19</time>
                </span>
                <span id="/1479.html" class="post-meta-item leancloud_visitors" data-flag-title="PHP高级特性学习总结" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>234</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1473.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1473.html" class="post-title-link" itemprop="url">PHP高级特性五之时间处理</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>PHP中的时间处理函数是非常常用的，在这里我们介绍的主要内容有</p>
                  <h2 id="UNIX时间戳"><a href="#UNIX时间戳" class="headerlink" title="UNIX时间戳"></a>UNIX时间戳</h2>
                  <p>以整数表示格林威治标准时间，英文叫做 timestamp，例如 11230499325，它在UNIX系统中是以32位存储的。从协调世界时1970年1月1日0时0分0秒起至现在的总秒数，不考虑闰秒。 作用：方便我们计算使用（参于运算）。</p>
                  <h2 id="获取时间函数"><a href="#获取时间函数" class="headerlink" title="获取时间函数"></a>获取时间函数</h2>
                  <h3 id="1-int-time-void"><a href="#1-int-time-void" class="headerlink" title="1.int time ( void )"></a>1.int time ( void )</h3>
                  <p>返回自从 Unix 纪元（格林威治时间 1970 年 1 月 1 日 00:00:00）到当前时间的秒数，即返回的就是UNIX时间戳。</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span> </span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> time();</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"> <span class="number">1426741342</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="2-array-getdate-int-timestamp-array-getDate-int-timestamp"><a href="#2-array-getdate-int-timestamp-array-getDate-int-timestamp" class="headerlink" title="2.array getdate ( [int timestamp] )/array getDate ( [int timestamp] )"></a>2.array getdate ( [int timestamp] )/array getDate ( [int timestamp] )</h3>
                  <p>可以通过传入时间戳获得时间，也可以不传参数获取时间。例如下面的例子获取了当前时间，返回类型是一个数组。</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span> </span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> <span class="string">"&lt;pre&gt;"</span>;</span></span><br><span class="line"><span class="php">	print_r(getDate());  <span class="comment">//或者getdate();</span></span></span><br><span class="line"><span class="php">	<span class="keyword">echo</span> <span class="string">"&lt;/pre&gt;"</span>;</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight php">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">Array</span></span><br><span class="line">(</span><br><span class="line">    [seconds] =&gt; <span class="number">4</span></span><br><span class="line">    [minutes] =&gt; <span class="number">6</span></span><br><span class="line">    [hours] =&gt; <span class="number">5</span></span><br><span class="line">    [mday] =&gt; <span class="number">19</span></span><br><span class="line">    [wday] =&gt; <span class="number">4</span></span><br><span class="line">    [mon] =&gt; <span class="number">3</span></span><br><span class="line">    [year] =&gt; <span class="number">2015</span></span><br><span class="line">    [yday] =&gt; <span class="number">77</span></span><br><span class="line">    [weekday] =&gt; Thursday</span><br><span class="line">    [month] =&gt; March</span><br><span class="line">    [<span class="number">0</span>] =&gt; <span class="number">1426741564</span></span><br><span class="line">)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>数组各个元素的说明如下</p>
                  <p>键名</p>
                  <p>说明</p>
                  <p>返回值例子</p>
                  <p>“seconds”</p>
                  <p>秒的数字表示</p>
                  <p>0 到 59</p>
                  <p>“minutes”</p>
                  <p>分钟的数字表示</p>
                  <p>0 到 59</p>
                  <p>“hours”</p>
                  <p>小时的数字表示</p>
                  <p>0 到 23</p>
                  <p>“mday”</p>
                  <p>月份中第几天的数字表示</p>
                  <p>1 到 31</p>
                  <p>“wday”</p>
                  <p>星期中第几天的数字表示</p>
                  <p>0（表示星期天）到 6（表示星期六）</p>
                  <p>“mon”</p>
                  <p>月份的数字表示</p>
                  <p>1 到 12</p>
                  <p>“year”</p>
                  <p>4 位数字表示的完整年份</p>
                  <p>例如：1999 或 2003</p>
                  <p>“yday”</p>
                  <p>一年中第几天的数字表示</p>
                  <p>0 到 365</p>
                  <p>“weekday”</p>
                  <p>星期几的完整文本表示</p>
                  <p>Sunday 到 Saturday</p>
                  <p>“month”</p>
                  <p>月份的完整文本表示</p>
                  <p>January&gt; 到 December</p>
                  <p>可以传入时间戳参数，如下所示</p>
                  <figure class="highlight reasonml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php </span><br><span class="line">	echo <span class="string">"&lt;pre&gt;"</span>;</span><br><span class="line">	print<span class="constructor">_r(<span class="params">getDate</span>(<span class="params">time</span>()</span>+<span class="number">60</span>*<span class="number">60</span>*<span class="number">24</span>));</span><br><span class="line">	print<span class="constructor">_r(<span class="params">getdate</span>(<span class="params">time</span>()</span>));</span><br><span class="line">	echo <span class="string">"&lt;/pre&gt;"</span>;</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="时间戳转日期"><a href="#时间戳转日期" class="headerlink" title="时间戳转日期"></a>时间戳转日期</h2>
                  <h3 id="1-string-date-string-format-int-timestamp"><a href="#1-string-date-string-format-int-timestamp" class="headerlink" title="1.string date ( string format [, int timestamp] )"></a>1.string date ( string format [, int timestamp] )</h3>
                  <p>返回将整数 timestamp 按照给定的格式字串而产生的字符串。如果没有给出时间戳则使用本地当前时间。换句话说，timestamp 是可选的，默认值为 time()。</p>
                  <figure class="highlight sqf">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line"> <span class="built_in">echo</span> <span class="built_in">date</span>(<span class="string">"Y-m-d H:i:s"</span>).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line"> <span class="built_in">echo</span> <span class="built_in">date</span>(<span class="string">"Y-m-d H:i:s"</span>,<span class="built_in">time</span>()).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line"> <span class="built_in">echo</span> <span class="built_in">date</span>(<span class="string">"Y-m-d H:i:s"</span>,<span class="built_in">time</span>()+<span class="number">60</span>*<span class="number">60</span>*<span class="number">24</span>).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">2015</span><span class="number">-03</span><span class="number">-19</span> <span class="number">05</span>:<span class="number">45</span>:<span class="number">49</span></span><br><span class="line"><span class="number">2015</span><span class="number">-03</span><span class="number">-19</span> <span class="number">05</span>:<span class="number">45</span>:<span class="number">49</span></span><br><span class="line"><span class="number">2015</span><span class="number">-03</span><span class="number">-20</span> <span class="number">05</span>:<span class="number">45</span>:<span class="number">49</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>下面是格式化的字符表</p>
                  <p>format 字符</p>
                  <p>说明</p>
                  <p>返回值例子</p>
                  <p>日</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>d</p>
                  <p>月份中的第几天，有前导零的 2 位数字</p>
                  <p>01 到 31</p>
                  <p>D</p>
                  <p>星期中的第几天，文本表示，3 个字母</p>
                  <p>Mon 到 Sun</p>
                  <p>j</p>
                  <p>月份中的第几天，没有前导零</p>
                  <p>1 到 31</p>
                  <p>l（“L”的小写字母）</p>
                  <p>星期几，完整的文本格式</p>
                  <p>Sunday 到 Saturday</p>
                  <p>N</p>
                  <p>ISO-8601 格式数字表示的星期中的第几天（PHP 5.1.0 新加）</p>
                  <p>1（表示星期一）到 7（表示星期天）</p>
                  <p>S</p>
                  <p>每月天数后面的英文后缀，2 个字符</p>
                  <p>st，nd，rd 或者 th。可以和 j 一起用</p>
                  <p>w</p>
                  <p>星期中的第几天，数字表示</p>
                  <p>0（表示星期天）到 6（表示星期六）</p>
                  <p>z</p>
                  <p>年份中的第几天</p>
                  <p>0 到 366</p>
                  <p>星期</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>W</p>
                  <p>ISO-8601 格式年份中的第几周，每周从星期一开始（PHP 4.1.0 新加的）</p>
                  <p>例如：42（当年的第 42 周）</p>
                  <p>月</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>F</p>
                  <p>月份，完整的文本格式，例如 January 或者 March</p>
                  <p>January 到 December</p>
                  <p>m</p>
                  <p>数字表示的月份，有前导零</p>
                  <p>01 到 12</p>
                  <p>M</p>
                  <p>三个字母缩写表示的月份</p>
                  <p>Jan 到 Dec</p>
                  <p>n</p>
                  <p>数字表示的月份，没有前导零</p>
                  <p>1 到 12</p>
                  <p>t</p>
                  <p>给定月份所应有的天数</p>
                  <p>28 到 31</p>
                  <p>年</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>L</p>
                  <p>是否为闰年</p>
                  <p>如果是闰年为 1，否则为 0</p>
                  <p>o</p>
                  <p>ISO-8601 格式年份数字。这和 Y 的值相同，只除了如果 ISO 的星期数（W）属于前一年或下一年，则用那一年。（PHP 5.1.0 新加）</p>
                  <p>Examples: 1999 or 2003</p>
                  <p>Y</p>
                  <p>4 位数字完整表示的年份</p>
                  <p>例如：1999 或 2003</p>
                  <p>y</p>
                  <p>2 位数字表示的年份</p>
                  <p>例如：99 或 03</p>
                  <p>时间</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>a</p>
                  <p>小写的上午和下午值</p>
                  <p>am 或 pm</p>
                  <p>A</p>
                  <p>大写的上午和下午值</p>
                  <p>AM 或 PM</p>
                  <p>B</p>
                  <p>Swatch Internet 标准时</p>
                  <p>000 到 999</p>
                  <p>g</p>
                  <p>小时，12 小时格式，没有前导零</p>
                  <p>1 到 12</p>
                  <p>G</p>
                  <p>小时，24 小时格式，没有前导零</p>
                  <p>0 到 23</p>
                  <p>h</p>
                  <p>小时，12 小时格式，有前导零</p>
                  <p>01 到 12</p>
                  <p>H</p>
                  <p>小时，24 小时格式，有前导零</p>
                  <p>00 到 23</p>
                  <p>i</p>
                  <p>有前导零的分钟数</p>
                  <p>00 到 59&gt;</p>
                  <p>s</p>
                  <p>秒数，有前导零</p>
                  <p>00 到 59&gt;</p>
                  <p>时区</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>e</p>
                  <p>时区标识（PHP 5.1.0 新加）</p>
                  <p>例如：UTC，GMT，Atlantic/Azores</p>
                  <p>I</p>
                  <p>是否为夏令时</p>
                  <p>如果是夏令时为 1，否则为 0</p>
                  <p>O</p>
                  <p>与格林威治时间相差的小时数</p>
                  <p>例如：+0200</p>
                  <p>T</p>
                  <p>本机所在的时区</p>
                  <p>例如：EST，MDT（【译者注】在 Windows 下为完整文本格式，例如“Eastern Standard Time”，中文版会显示“中国标准时间”）。</p>
                  <p>Z</p>
                  <p>时差偏移量的秒数。UTC 西边的时区偏移量总是负的，UTC 东边的时区偏移量总是正的。</p>
                  <p>-43200 到 43200</p>
                  <p>完整的日期／时间</p>
                  <p>-—</p>
                  <p>-—</p>
                  <p>c</p>
                  <p>ISO 8601 格式的日期（PHP 5 新加）</p>
                  <p>2004-02-12T15:19:21+00:00</p>
                  <p>r</p>
                  <p>RFC 822 格式的日期</p>
                  <p>例如：Thu, 21 Dec 2000 16:01:07 +0200</p>
                  <p>U</p>
                  <p>从 Unix 纪元（January 1 1970 00:00:00 GMT）开始至今的秒数</p>
                  <p>参见 time()</p>
                  <h2 id="日期转时间戳"><a href="#日期转时间戳" class="headerlink" title="日期转时间戳"></a>日期转时间戳</h2>
                  <h3 id="1-int-mktime-int-hour-int-minute-int-second-int-month-int-day-int-year-int-is-dst"><a href="#1-int-mktime-int-hour-int-minute-int-second-int-month-int-day-int-year-int-is-dst" class="headerlink" title="1.int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )"></a>1.int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )</h3>
                  <p>根据给出的参数返回 Unix 时间戳。时间戳是一个长整数，包含了从 Unix 纪元（January 1 1970 00:00:00 GMT）到给定时间的秒数。参数可以从右向左省略，任何省略的参数会被设置成本地日期和时间的当前值。 例如我们获取1997年12月1日的时间戳</p>
                  <figure class="highlight lsl">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">echo mktime(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">12</span>, <span class="number">1</span>, <span class="number">1997</span>).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"> <span class="number">880934400</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>在这里如果我们的年份如果填2位数，函数可以智能给我们转化，例如第六个参数填 97，那么则会识别为 1997年，如果填 03，那么则会识别为 2003年。那么有的小伙伴就问了，两个之间的分界点是哪一年哪一月哪一日呢？我们来看下面的例子</p>
                  <figure class="highlight lsl">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">	echo date(<span class="string">"m-d-Y"</span>, mktime(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">12</span>, <span class="number">32</span>, <span class="number">1997</span>)).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">	echo date(<span class="string">"M-d-Y"</span>, mktime(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">14</span>, <span class="number">98</span>)).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">	echo date(<span class="string">"M-d-Y"</span>, mktime(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">1</span>, <span class="number">03</span>)).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">	echo date(<span class="string">"M-d-Y"</span>, mktime(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">19</span>, <span class="number">38</span>)).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">	echo date(<span class="string">"M-d-Y"</span>, mktime(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">20</span>, <span class="number">38</span>)).<span class="string">"&lt;br&gt;"</span>;</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">01</span><span class="number">-01</span><span class="number">-1998</span></span><br><span class="line">Mar<span class="number">-14</span><span class="number">-1998</span></span><br><span class="line">Jan<span class="number">-01</span><span class="number">-2003</span></span><br><span class="line">Jan<span class="number">-19</span><span class="number">-2038</span></span><br><span class="line">Jan<span class="number">-01</span><span class="number">-1970</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>在这里我们可以发现，当我们输入2038年的1月19日时，可以正常识别为2038-1-19，不过当我们输入2038年1月20日时，则识别成了1970-1-1，可见分界点就在2038-1-19这一天。 在这里有个有趣的2038年问题，扩展阅读一下</p>
                  <blockquote>
                    <p>在计算机应用上，2038年问题可能会导致某些软件在2038年无法正常工作。所有使用UNIX时间表示时间的程序都将受其影响，因为它们以自1970年1月1日经过的秒数（忽略闰秒）来表示时间。这种时间表示法在类Unix（Unix-like）操作系统上是一个标准，并会影响以其C编程语言开发给其他大部份操作系统使用的软件。在大部份的32位操作系统上，此“time_t”数据模式使用一个有正负号的32位元整数(signedint32)存储计算的秒数。依照此“time_t”标准，在此格式能被表示的最后时间是2038年1月19日03:14:07，星期二（UTC）。超过此一瞬间，时间将会被掩盖（wrap around）且在内部被表示为一个负数，并造成程序无法工作，因为它们无法将此时间识别为2038年，而可能会依个别实作而跳回1970年或1901年。错误的计算及动作可能因此产生。</p>
                  </blockquote>
                  <h2 id="修改PHP默认时区"><a href="#修改PHP默认时区" class="headerlink" title="修改PHP默认时区"></a>修改PHP默认时区</h2>
                  <p>我们来看下面一个例子，是上面所说的调用date方法返回的时间。</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php"> <span class="keyword">echo</span> date(<span class="string">"Y-m-d H:i:s"</span>);</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">2015</span><span class="number">-03</span><span class="number">-19</span> <span class="number">06</span>:<span class="number">03</span>:<span class="number">22</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>而现在我的电脑系统时间为</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">2015</span><span class="number">-03</span><span class="number">-19</span> <span class="number">14</span>:<span class="number">03</span>:<span class="number">22</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>这是什么原因？很简单，PHP程序中返回的是中时区的格林威治时间，而我们国家使用的是东八区区时，所以程序中的时间会慢8个小时。所以，我们只需要设置一下时区即可。</p>
                  <h3 id="1-设置PHP-ini文件"><a href="#1-设置PHP-ini文件" class="headerlink" title="1.设置PHP.ini文件"></a>1.设置PHP.ini文件</h3>
                  <p>这种方法是通用的设置方法，一次设置，其他所有编写的PHP文件都会生效，而且不需要在程序中设置了。只需要修改</p>
                  <figure class="highlight ini">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="section">[Date]</span></span><br><span class="line"><span class="comment">; Defines the default timezone used by the date functions</span></span><br><span class="line"><span class="comment">; http://php.net/date.timezone</span></span><br><span class="line"><span class="attr">date.timezone</span> = PRC</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>默认的 date.timezone = UTC，在这里我们修改为中国的代号PRC即可。修改完之后记得重启服务器才能生效。 再运行程序，发现时间已经很准确了。</p>
                  <h3 id="2-在程序中设置"><a href="#2-在程序中设置" class="headerlink" title="2.在程序中设置"></a>2.在程序中设置</h3>
                  <figure class="highlight ceylon">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;?php</span><br><span class="line">date<span class="number">_</span><span class="keyword">default</span><span class="number">_</span>timezone<span class="number">_</span>set(<span class="string">"PRC"</span>);</span><br><span class="line">date<span class="number">_</span><span class="keyword">default</span><span class="number">_</span>timezone<span class="number">_</span>set(<span class="string">"Asia/Shanghai"</span>);</span><br><span class="line">date<span class="number">_</span><span class="keyword">default</span><span class="number">_</span>timezone<span class="number">_</span>set(<span class="string">"Gtc/GET-8"</span>);</span><br><span class="line">?&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>上面三行语句均可使用，效果相同。第一个是设置中国时区，第二个是设置上海时区，第三个是设置东八区区时。 <strong>在此附亚洲区时</strong></p>
                  <p>Asia/Aden</p>
                  <p>Asia/Almaty</p>
                  <p>Asia/Amman</p>
                  <p>Asia/Anadyr</p>
                  <p>Asia/Aqtau</p>
                  <p>Asia/Aqtobe</p>
                  <p>Asia/Ashgabat</p>
                  <p>Asia/Ashkhabad</p>
                  <p>Asia/Baghdad</p>
                  <p>Asia/Bahrain</p>
                  <p>Asia/Baku</p>
                  <p>Asia/Bangkok</p>
                  <p>Asia/Beirut</p>
                  <p>Asia/Bishkek</p>
                  <p>Asia/Brunei</p>
                  <p>Asia/Calcutta</p>
                  <p>Asia/Chita</p>
                  <p>Asia/Choibalsan</p>
                  <p>Asia/Chongqing</p>
                  <p>Asia/Chungking</p>
                  <p>Asia/Colombo</p>
                  <p>Asia/Dacca</p>
                  <p>Asia/Damascus</p>
                  <p>Asia/Dhaka</p>
                  <p>Asia/Dili</p>
                  <p>Asia/Dubai</p>
                  <p>Asia/Dushanbe</p>
                  <p>Asia/Gaza</p>
                  <p>Asia/Harbin</p>
                  <p>Asia/Hebron</p>
                  <p>Asia/Ho_Chi_Minh</p>
                  <p>Asia/Hong_Kong</p>
                  <p>Asia/Hovd</p>
                  <p>Asia/Irkutsk</p>
                  <p>Asia/Istanbul</p>
                  <p>Asia/Jakarta</p>
                  <p>Asia/Jayapura</p>
                  <p>Asia/Jerusalem</p>
                  <p>Asia/Kabul</p>
                  <p>Asia/Kamchatka</p>
                  <p>Asia/Karachi</p>
                  <p>Asia/Kashgar</p>
                  <p>Asia/Kathmandu</p>
                  <p>Asia/Katmandu</p>
                  <p>Asia/Khandyga</p>
                  <p>Asia/Kolkata</p>
                  <p>Asia/Krasnoyarsk</p>
                  <p>Asia/Kuala_Lumpur</p>
                  <p>Asia/Kuching</p>
                  <p>Asia/Kuwait</p>
                  <p>Asia/Macao</p>
                  <p>Asia/Macau</p>
                  <p>Asia/Magadan</p>
                  <p>Asia/Makassar</p>
                  <p>Asia/Manila</p>
                  <p>Asia/Muscat</p>
                  <p>Asia/Nicosia</p>
                  <p>Asia/Novokuznetsk</p>
                  <p>Asia/Novosibirsk</p>
                  <p>Asia/Omsk</p>
                  <p>Asia/Oral</p>
                  <p>Asia/Phnom_Penh</p>
                  <p>Asia/Pontianak</p>
                  <p>Asia/Pyongyang</p>
                  <p>Asia/Qatar</p>
                  <p>Asia/Qyzylorda</p>
                  <p>Asia/Rangoon</p>
                  <p>Asia/Riyadh</p>
                  <p>Asia/Saigon</p>
                  <p>Asia/Sakhalin</p>
                  <p>Asia/Samarkand</p>
                  <p>Asia/Seoul</p>
                  <p>Asia/Shanghai</p>
                  <p>Asia/Singapore</p>
                  <p>Asia/Srednekolymsk</p>
                  <p>Asia/Taipei</p>
                  <p>Asia/Tashkent</p>
                  <p>Asia/Tbilisi</p>
                  <p>Asia/Tehran</p>
                  <p>Asia/Tel_Aviv</p>
                  <p>Asia/Thimbu</p>
                  <p>Asia/Thimphu</p>
                  <p>Asia/Tokyo</p>
                  <p>Asia/Ujung_Pandang</p>
                  <p>Asia/Ulaanbaatar</p>
                  <p>Asia/Ulan_Bator</p>
                  <p>Asia/Urumqi</p>
                  <p>Asia/Ust-Nera</p>
                  <p>Asia/Vientiane</p>
                  <p>Asia/Vladivostok</p>
                  <p>Asia/Yakutsk</p>
                  <p>Asia/Yekaterinburg</p>
                  <p>Asia/Yerevan</p>
                  <h2 id="微妙精确计算"><a href="#微妙精确计算" class="headerlink" title="微妙精确计算"></a>微妙精确计算</h2>
                  <h3 id="1-mixed-microtime-bool-get-as-float"><a href="#1-mixed-microtime-bool-get-as-float" class="headerlink" title="1.mixed microtime ( [bool get_as_float] )"></a>1.mixed microtime ( [bool get_as_float] )</h3>
                  <p>microtime() 当前 Unix 时间戳以及微秒数。本函数仅在支持 gettimeofday() 系统调用的操作系统下可用。 如果调用时不带可选参数，本函数以 “msec sec” 的格式返回一个字符串，其中 sec 是自 Unix 纪元（0:00:00 January 1, 1970 GMT）起到现在的秒数，msec 是微秒部分。字符串的两部分都是以秒为单位返回的。如果传入true参数，那么则会返回sec.msec的形式，是一个浮点数。 我们大多数用来计算程序执行时间。</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"><span class="php">	<span class="class"><span class="keyword">class</span> <span class="title">Timer</span> </span>&#123;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $startTime; <span class="comment">//开始时间</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $stopTime;  <span class="comment">//结束时间</span></span></span><br><span class="line"><span class="php">		<span class="keyword">private</span> $count = <span class="number">0</span>;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//初始化两个时间为0</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;startTime=<span class="number">0</span>;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;stopTime=<span class="number">0</span>;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//设置开始时间</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">start</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;startTime=microtime(<span class="keyword">true</span>);</span></span><br><span class="line"><span class="php">			<span class="keyword">echo</span> <span class="keyword">$this</span>-&gt;startTime.<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//设置结束时间</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">stop</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;stopTime=microtime(<span class="keyword">true</span>);</span></span><br><span class="line"><span class="php">			<span class="keyword">echo</span> <span class="keyword">$this</span>-&gt;stopTime.<span class="string">"&lt;br&gt;"</span>;</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//计算过了多长时间</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">spent</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;start();</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;dosomething();</span></span><br><span class="line"><span class="php">			<span class="keyword">$this</span>-&gt;stop();</span></span><br><span class="line"><span class="php">			<span class="keyword">return</span> (<span class="keyword">$this</span>-&gt;stopTime - <span class="keyword">$this</span>-&gt;startTime); </span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">		</span></span><br><span class="line"><span class="php">		<span class="comment">//程序执行某些任务</span></span></span><br><span class="line"><span class="php">		<span class="function"><span class="keyword">function</span> <span class="title">dosomething</span><span class="params">()</span></span>&#123;</span></span><br><span class="line"><span class="php">			<span class="keyword">for</span>($i=<span class="number">0</span>; $i&lt;<span class="number">10000</span>; $i++)</span></span><br><span class="line"><span class="php">			&#123;</span></span><br><span class="line"><span class="php">				<span class="keyword">$this</span>-&gt;count ++;</span></span><br><span class="line"><span class="php">			&#125;	</span></span><br><span class="line"><span class="php">		&#125;</span></span><br><span class="line"><span class="php">	&#125;</span></span><br><span class="line"><span class="php">	</span></span><br><span class="line"><span class="php">$timer = <span class="keyword">new</span> Timer();</span></span><br><span class="line"></span><br><span class="line"><span class="php"><span class="keyword">echo</span> $timer-&gt;spent();</span></span><br><span class="line"></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">1426746064.4247</span></span><br><span class="line"><span class="number">1426746064.4267</span></span><br><span class="line"><span class="number">0.0019998550415039</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>可以发现，程序执行用了 1.99 微秒。 好，关于PHP中的时间问题，我们就介绍到这里，希望对大家有帮助。</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-19 13:39:09" itemprop="dateCreated datePublished" datetime="2015-03-19T13:39:09+08:00">2015-03-19</time>
                </span>
                <span id="/1473.html" class="post-meta-item leancloud_visitors" data-flag-title="PHP高级特性五之时间处理" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>6.7k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>6 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1470.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1470.html" class="post-title-link" itemprop="url">PHP高级特性四之SMTP邮件发送</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>PHP的邮件发送最常见的便是SMTP，通过编写一个Smtp类，设置好smtp服务器，邮箱用户名，密码，即可实现邮件的发送</p>
                  <h2 id="邮件发送"><a href="#邮件发送" class="headerlink" title="邮件发送"></a>邮件发送</h2>
                  <p>邮件发送的类如下，文件名叫做</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">email.<span class="keyword">class</span>.<span class="symbol">php</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"></span><br><span class="line"><span class="php"><span class="comment">/* smtp class */</span></span></span><br><span class="line"><span class="php"><span class="class"><span class="keyword">class</span> <span class="title">smtp</span> </span>&#123;</span></span><br><span class="line"><span class="php">    <span class="comment">/* Public Variables */</span></span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $smtp_port;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $time_out;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $host_name;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $log_file;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $relay_host;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $debug;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $auth;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $user;</span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $pass;</span></span><br><span class="line"><span class="php">    <span class="comment">/* Private Variables */</span></span></span><br><span class="line"><span class="php">    <span class="keyword">var</span> $sock;</span></span><br><span class="line"><span class="php">    <span class="comment">/* Constractor */</span></span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp</span><span class="params">($relay_host = <span class="string">""</span>, $smtp_port = <span class="number">25</span>, $auth = false, $user, $pass)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;debug = <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;smtp_port = $smtp_port;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;relay_host = $relay_host;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;time_out = <span class="number">30</span>; <span class="comment">//is used in fsockopen()</span></span></span><br><span class="line"><span class="php">        <span class="comment">//</span></span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;auth = $auth; <span class="comment">//auth</span></span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;user = $user;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;pass = $pass;</span></span><br><span class="line"><span class="php">        <span class="comment">//</span></span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;host_name = <span class="string">"localhost"</span>; <span class="comment">//is used in HELO command</span></span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;log_file = <span class="string">""</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;sock = <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="comment">/* Main Function */</span></span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">sendmail</span><span class="params">($to, $from, $subject = <span class="string">""</span>, $body = <span class="string">""</span>, $mailtype, $cc = <span class="string">""</span>, $bcc = <span class="string">""</span>, $additional_headers = <span class="string">""</span>)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        $mail_from = <span class="keyword">$this</span>-&gt;get_address(<span class="keyword">$this</span>-&gt;strip_comment($from));</span></span><br><span class="line"><span class="php">        $body = preg_replace(<span class="string">"/(^|(\r\n))(\.)/"</span>, <span class="string">"\1.\3"</span>, $body);</span></span><br><span class="line"><span class="php">        $header = <span class="string">"MIME-Version:1.0\r\n"</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> ($mailtype == <span class="string">"HTML"</span>) &#123;</span></span><br><span class="line"><span class="php">            $header.= <span class="string">"Content-Type:text/html\r\n"</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        $header.= <span class="string">"To: "</span> . $to . <span class="string">"\r\n"</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> ($cc != <span class="string">""</span>) &#123;</span></span><br><span class="line"><span class="php">            $header.= <span class="string">"Cc: "</span> . $cc . <span class="string">"\r\n"</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        $header.= <span class="string">"From: $from&lt;"</span> . $from . <span class="string">"&gt;\r\n"</span>;</span></span><br><span class="line"><span class="php">        $header.= <span class="string">"Subject: "</span> . $subject . <span class="string">"\r\n"</span>;</span></span><br><span class="line"><span class="php">        $header.= $additional_headers;</span></span><br><span class="line"><span class="php">        $header.= <span class="string">"Date: "</span> . date(<span class="string">"r"</span>) . <span class="string">"\r\n"</span>;</span></span><br><span class="line"><span class="php">        $header.= <span class="string">"X-Mailer:By Redhat (PHP/"</span> . phpversion() . <span class="string">")\r\n"</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">list</span>($msec, $sec) = explode(<span class="string">" "</span>, microtime());</span></span><br><span class="line"><span class="php">        $header.= <span class="string">"Message-ID: &lt;"</span> . date(<span class="string">"YmdHis"</span>, $sec) . <span class="string">"."</span> . ($msec * <span class="number">1000000</span>) . <span class="string">"."</span> . $mail_from . <span class="string">"&gt;\r\n"</span>;</span></span><br><span class="line"><span class="php">        $TO = explode(<span class="string">","</span>, <span class="keyword">$this</span>-&gt;strip_comment($to));</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> ($cc != <span class="string">""</span>) &#123;</span></span><br><span class="line"><span class="php">            $TO = array_merge($TO, explode(<span class="string">","</span>, <span class="keyword">$this</span>-&gt;strip_comment($cc)));</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> ($bcc != <span class="string">""</span>) &#123;</span></span><br><span class="line"><span class="php">            $TO = array_merge($TO, explode(<span class="string">","</span>, <span class="keyword">$this</span>-&gt;strip_comment($bcc)));</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        $sent = <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">foreach</span> ($TO <span class="keyword">as</span> $rcpt_to) &#123;</span></span><br><span class="line"><span class="php">            $rcpt_to = <span class="keyword">$this</span>-&gt;get_address($rcpt_to);</span></span><br><span class="line"><span class="php">            <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_sockopen($rcpt_to)) &#123;</span></span><br><span class="line"><span class="php">                <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Cannot send email to "</span> . $rcpt_to . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">                $sent = <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">                <span class="keyword">continue</span>;</span></span><br><span class="line"><span class="php">            &#125;</span></span><br><span class="line"><span class="php">            <span class="keyword">if</span> (<span class="keyword">$this</span>-&gt;smtp_send(<span class="keyword">$this</span>-&gt;host_name, $mail_from, $rcpt_to, $header, $body)) &#123;</span></span><br><span class="line"><span class="php">                <span class="keyword">$this</span>-&gt;log_write(<span class="string">"E-mail has been sent to &lt;"</span> . $rcpt_to . <span class="string">"&gt;\n"</span>);</span></span><br><span class="line"><span class="php">            &#125; <span class="keyword">else</span> &#123;</span></span><br><span class="line"><span class="php">                <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Cannot send email to &lt;"</span> . $rcpt_to . <span class="string">"&gt;\n"</span>);</span></span><br><span class="line"><span class="php">                $sent = <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">            &#125;</span></span><br><span class="line"><span class="php">            fclose(<span class="keyword">$this</span>-&gt;sock);</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Disconnected from remote host\n"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> $sent;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="comment">/* Private Functions */</span></span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_send</span><span class="params">($helo, $from, $to, $header, $body = <span class="string">""</span>)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">"HELO"</span>, $helo)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending HELO command"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="comment">//auth</span></span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (<span class="keyword">$this</span>-&gt;auth) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">"AUTH LOGIN"</span>, base64_encode(<span class="keyword">$this</span>-&gt;user))) &#123;</span></span><br><span class="line"><span class="php">                <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending HELO command"</span>);</span></span><br><span class="line"><span class="php">            &#125;</span></span><br><span class="line"><span class="php">            <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">""</span>, base64_encode(<span class="keyword">$this</span>-&gt;pass))) &#123;</span></span><br><span class="line"><span class="php">                <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending HELO command"</span>);</span></span><br><span class="line"><span class="php">            &#125;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="comment">//</span></span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">"MAIL"</span>, <span class="string">"FROM:&lt;"</span> . $from . <span class="string">"&gt;"</span>)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending MAIL FROM command"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">"RCPT"</span>, <span class="string">"TO:&lt;"</span> . $to . <span class="string">"&gt;"</span>)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending RCPT TO command"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">"DATA"</span>)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending DATA command"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_message($header, $body)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending message"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_eom()) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt; [EOM]"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!<span class="keyword">$this</span>-&gt;smtp_putcmd(<span class="string">"QUIT"</span>)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_error(<span class="string">"sending QUIT command"</span>);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_sockopen</span><span class="params">($address)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (<span class="keyword">$this</span>-&gt;relay_host == <span class="string">""</span>) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_sockopen_mx($address);</span></span><br><span class="line"><span class="php">        &#125; <span class="keyword">else</span> &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_sockopen_relay();</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_sockopen_relay</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Trying to "</span> . <span class="keyword">$this</span>-&gt;relay_host . <span class="string">":"</span> . <span class="keyword">$this</span>-&gt;smtp_port . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;sock = @fsockopen(<span class="keyword">$this</span>-&gt;relay_host, <span class="keyword">$this</span>-&gt;smtp_port, $errno, $errstr, <span class="keyword">$this</span>-&gt;time_out);</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!(<span class="keyword">$this</span>-&gt;sock &amp;&amp; <span class="keyword">$this</span>-&gt;smtp_ok())) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Cannot connenct to relay host "</span> . <span class="keyword">$this</span>-&gt;relay_host . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: "</span> . $errstr . <span class="string">" ("</span> . $errno . <span class="string">")\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Connected to relay host "</span> . <span class="keyword">$this</span>-&gt;relay_host . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">TRUE</span>;;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_sockopen_mx</span><span class="params">($address)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        $domain = preg_replace(<span class="string">"/^.+@([^@]+)$/"</span>, <span class="string">"\1"</span>, $address);</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!@getmxrr($domain, $MXHOSTS)) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Cannot resolve MX \""</span> . $domain . <span class="string">"\"\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">foreach</span> ($MXHOSTS <span class="keyword">as</span> $host) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Trying to "</span> . $host . <span class="string">":"</span> . <span class="keyword">$this</span>-&gt;smtp_port . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;sock = @fsockopen($host, <span class="keyword">$this</span>-&gt;smtp_port, $errno, $errstr, <span class="keyword">$this</span>-&gt;time_out);</span></span><br><span class="line"><span class="php">            <span class="keyword">if</span> (!(<span class="keyword">$this</span>-&gt;sock &amp;&amp; <span class="keyword">$this</span>-&gt;smtp_ok())) &#123;</span></span><br><span class="line"><span class="php">                <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Warning: Cannot connect to mx host "</span> . $host . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">                <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: "</span> . $errstr . <span class="string">" ("</span> . $errno . <span class="string">")\n"</span>);</span></span><br><span class="line"><span class="php">                <span class="keyword">continue</span>;</span></span><br><span class="line"><span class="php">            &#125;</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Connected to mx host "</span> . $host . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Cannot connect to any mx hosts ("</span> . implode(<span class="string">", "</span>, $MXHOSTS) . <span class="string">")\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_message</span><span class="params">($header, $body)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        fputs(<span class="keyword">$this</span>-&gt;sock, $header . <span class="string">"\r\n"</span> . $body);</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;smtp_debug(<span class="string">"&gt; "</span> . str_replace(<span class="string">"\r\n"</span>, <span class="string">"\n"</span> . <span class="string">"&gt; "</span>, $header . <span class="string">"\n&gt; "</span> . $body . <span class="string">"\n&gt; "</span>));</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_eom</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="php">        fputs(<span class="keyword">$this</span>-&gt;sock, <span class="string">"\r\n.\r\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;smtp_debug(<span class="string">". [EOM]\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_ok();</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_ok</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="php">        $response = str_replace(<span class="string">"\r\n"</span>, <span class="string">""</span>, fgets(<span class="keyword">$this</span>-&gt;sock, <span class="number">512</span>));</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;smtp_debug($response . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!preg_match(<span class="string">"/^[23]/"</span>, $response)) &#123;</span></span><br><span class="line"><span class="php">            fputs(<span class="keyword">$this</span>-&gt;sock, <span class="string">"QUIT\r\n"</span>);</span></span><br><span class="line"><span class="php">            fgets(<span class="keyword">$this</span>-&gt;sock, <span class="number">512</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Remote host returned \""</span> . $response . <span class="string">"\"\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_putcmd</span><span class="params">($cmd, $arg = <span class="string">""</span>)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> ($arg != <span class="string">""</span>) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">if</span> ($cmd == <span class="string">""</span>) $cmd = $arg;</span></span><br><span class="line"><span class="php">            <span class="keyword">else</span> $cmd = $cmd . <span class="string">" "</span> . $arg;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        fputs(<span class="keyword">$this</span>-&gt;sock, $cmd . <span class="string">"\r\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;smtp_debug(<span class="string">"&gt; "</span> . $cmd . <span class="string">"\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;smtp_ok();</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_error</span><span class="params">($string)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;log_write(<span class="string">"Error: Error occurred while "</span> . $string . <span class="string">".\n"</span>);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">FALSE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">log_write</span><span class="params">($message)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">$this</span>-&gt;smtp_debug($message);</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (<span class="keyword">$this</span>-&gt;log_file == <span class="string">""</span>) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        $message = date(<span class="string">"M d H:i:s "</span>) . get_current_user() . <span class="string">"["</span> . getmypid() . <span class="string">"]: "</span> . $message;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (!@file_exists(<span class="keyword">$this</span>-&gt;log_file) || !($fp = @fopen(<span class="keyword">$this</span>-&gt;log_file, <span class="string">"a"</span>))) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">$this</span>-&gt;smtp_debug(<span class="string">"Warning: Cannot open log file \""</span> . <span class="keyword">$this</span>-&gt;log_file . <span class="string">"\"\n"</span>);</span></span><br><span class="line"><span class="php">            <span class="keyword">return</span> <span class="keyword">FALSE</span>;;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        flock($fp, LOCK_EX);</span></span><br><span class="line"><span class="php">        fputs($fp, $message);</span></span><br><span class="line"><span class="php">        fclose($fp);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> <span class="keyword">TRUE</span>;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">strip_comment</span><span class="params">($address)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        $comment = <span class="string">"/\([^()]*\)/"</span>;</span></span><br><span class="line"><span class="php">        <span class="keyword">while</span> (preg_match($comment, $address)) &#123;</span></span><br><span class="line"><span class="php">            $address = preg_replace($comment, <span class="string">""</span>, $address);</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> $address;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">get_address</span><span class="params">($address)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        $address = preg_replace(<span class="string">"/([ \t\r\n])+/"</span>, <span class="string">""</span>, $address);</span></span><br><span class="line"><span class="php">        $address = preg_replace(<span class="string">"/^.*&lt;(.+)&gt;.*$/"</span>, <span class="string">"\1"</span>, $address);</span></span><br><span class="line"><span class="php">        <span class="keyword">return</span> $address;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">    <span class="function"><span class="keyword">function</span> <span class="title">smtp_debug</span><span class="params">($message)</span> </span>&#123;</span></span><br><span class="line"><span class="php">        <span class="keyword">if</span> (<span class="keyword">$this</span>-&gt;debug) &#123;</span></span><br><span class="line"><span class="php">            <span class="keyword">echo</span> $message;</span></span><br><span class="line"><span class="php">        &#125;</span></span><br><span class="line"><span class="php">    &#125;</span></span><br><span class="line"><span class="php">&#125;</span></span><br><span class="line"><span class="php"><span class="meta">?&gt;</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>然后便是一个php文件引用该文件，设置好各种参数</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="meta">&lt;!DOCTYPE&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Content-Type"</span> <span class="attr">content</span>=<span class="string">"text/html; charset=utf-8"</span> /&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">title</span>&gt;</span>发送状态<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">		<span class="php"><span class="meta">&lt;?php</span></span></span><br><span class="line"></span><br><span class="line"><span class="php">			<span class="keyword">require_once</span> <span class="string">"email.class.php"</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//SMTP服务器</span></span></span><br><span class="line"><span class="php">			$smtpserver = <span class="string">"smtp.163.com"</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//SMTP端口号?</span></span></span><br><span class="line"><span class="php">			$smtpserverport = <span class="number">25</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//SMTP发邮件的邮箱</span></span></span><br><span class="line"><span class="php">			$smtpusermail = <span class="string">"cqc@163.com"</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//发给谁</span></span></span><br><span class="line"><span class="php">			$smtpemailto = $_POST[<span class="string">'toemail'</span>];</span></span><br><span class="line"><span class="php">			<span class="comment">//SMTP用户名，不加@163.com</span></span></span><br><span class="line"><span class="php">			$smtpuser = <span class="string">"cqc"</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//SMTP用户密码</span></span></span><br><span class="line"><span class="php">			$smtppass = <span class="string">"wtf"</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//主题</span></span></span><br><span class="line"><span class="php">			$mailtitle = $_POST[<span class="string">'topic'</span>];</span></span><br><span class="line"><span class="php">			<span class="comment">//构建内容</span></span></span><br><span class="line"><span class="php">			$mailcontent = <span class="string">"TA的名字 "</span>.$_POST[<span class="string">'name'</span>].<span class="string">"&lt;br&gt;内容: "</span>.$_POST[<span class="string">'content'</span>];</span></span><br><span class="line"><span class="php">			<span class="comment">//邮件内容为HTML格式</span></span></span><br><span class="line"><span class="php">			$mailtype = <span class="string">"HTML"</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//实例化对象</span></span></span><br><span class="line"><span class="php">			$smtp = <span class="keyword">new</span> smtp($smtpserver,$smtpserverport,<span class="keyword">true</span>,$smtpuser,$smtppass);</span></span><br><span class="line"><span class="php">			<span class="comment">//关闭调试信息</span></span></span><br><span class="line"><span class="php">			$smtp-&gt;debug = <span class="keyword">false</span>;</span></span><br><span class="line"><span class="php">			<span class="comment">//发送邮件</span></span></span><br><span class="line"><span class="php">			$state = $smtp-&gt;sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);</span></span><br><span class="line"><span class="php">			<span class="comment">//检查发送状态</span></span></span><br><span class="line"><span class="php">			<span class="keyword">if</span>($state==<span class="string">""</span>)&#123;</span></span><br><span class="line"><span class="php">				<span class="keyword">echo</span> <span class="string">"邮件发送失败，请检查密码或其他设置"</span>;</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span> <span class="keyword">if</span>(strlen($state)!=<span class="number">0</span>)&#123;</span></span><br><span class="line"><span class="php">			<span class="comment">//发送成功</span></span></span><br><span class="line"><span class="php">				<span class="keyword">echo</span> <span class="string">"邮件发送成功"</span>;</span></span><br><span class="line"><span class="php">			&#125;<span class="keyword">else</span>&#123;</span></span><br><span class="line"><span class="php">				<span class="keyword">echo</span> <span class="string">"未知错误"</span>;</span></span><br><span class="line"><span class="php">			&#125;</span></span><br><span class="line"></span><br><span class="line"><span class="php">		<span class="meta">?&gt;</span></span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>最后是一个表单提交，包括目的邮箱，主题，内容</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="meta">&lt;!DOCTYPE&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">"Content-Type"</span> <span class="attr">content</span>=<span class="string">"text/html; charset=utf-8"</span> /&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">title</span>&gt;</span>PHP利用SMTP发送邮件范例<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">"sendmail.php"</span> <span class="attr">method</span>=<span class="string">"post"</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">p</span>&gt;</span>收件人：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"toemail"</span> /&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">p</span>&gt;</span>标<span class="symbol">&amp;nbsp;</span><span class="symbol">&amp;nbsp;</span>题：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"topic"</span> /&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">p</span>&gt;</span>姓<span class="symbol">&amp;nbsp;</span><span class="symbol">&amp;nbsp;</span>名：<span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"text"</span> <span class="attr">name</span>=<span class="string">"name"</span> /&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">p</span>&gt;</span>内<span class="symbol">&amp;nbsp;</span><span class="symbol">&amp;nbsp;</span>容：<span class="tag">&lt;<span class="name">textarea</span> <span class="attr">name</span>=<span class="string">"content"</span> <span class="attr">cols</span>=<span class="string">"50"</span> <span class="attr">rows</span>=<span class="string">"5"</span>&gt;</span><span class="tag">&lt;/<span class="name">textarea</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">"submit"</span> <span class="attr">value</span>=<span class="string">"发送"</span>  /&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="代码下载"><a href="#代码下载" class="headerlink" title="代码下载"></a>代码下载</h2>
                  <p><a href="https://github.com/cqcre/sendmail" target="_blank" rel="noopener">代码下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-18 19:36:15" itemprop="dateCreated datePublished" datetime="2015-03-18T19:36:15+08:00">2015-03-18</time>
                </span>
                <span id="/1470.html" class="post-meta-item leancloud_visitors" data-flag-title="PHP高级特性四之SMTP邮件发送" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>8.9k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>8 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1458.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> 个人随笔 <i class="label-arrow"></i>
                  </a>
                  <a href="/1458.html" class="post-title-link" itemprop="url">开始备战了</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <p>博主来自山东大学，现在大三了，想保研北京航空航天大学。<a href="http://scse.buaa.edu.cn/buaa-css-web/articleDetail.action?firstSelId=f72041e7-c66e-4fc4-b8f2-ae0797744edb&amp;secondSelId=bd593072-feb6-49fe-bb75-06d01d42097c&amp;articleId=2d0691d0-535c-4940-8831-9d1b26b09759&amp;type=NEWS&amp;language=0" target="_blank" rel="noopener">去年的保研政策</a>，其中复试是这么规定的</p>
                  <blockquote>
                    <p>北京航空航天大学计算机学院 1、学院复试工作小组对申请者各项材料（含体格检查表及推免服务系统填写的网上报名志愿）进行综合评审，确定复试名单，通过“推免服务系统”发放复试通知。接到“推免服务系统”复试通知的申请者，须通过“推免服务系统”接受学院的复试通知。学院将对接受复试通知的申请者组织复试，申请者复试时需交纳复试费100元/人。 2、.复试形式：采取差额复试。复试内容包括C语言上机考试和综合面试两部分，C语言上机考试为资格考试，通过上机考试后方可进入综合面试环节，面试总成绩300分。综合面试内容包括英语能力、数理基础、专业素质、综合素质等四个方面的内容。 ⑴ 英语能力方面主要考核内容包括：口语、听力、现场阅读与翻译； ⑵ 数理基础方面主要考核内容包括：本专业研究方向应该掌握的数学基础理论（或离散数学，或其他基础理论知识）； ⑶ 专业素质方面主要考核内容包括：专业基础知识和专业综合能力。专业基础知识考核专业知识问题，考生；专业综合能力主要考核考生综合运用所学知识解决计算机领域具体应用问题（或设计问题，或工程问题）的能力，以考核考生的分析能力和专业综合能力。 ⑷ 综合素质方面主要考核内容包括：语言表达能力、逻辑思维能力、对学科热点的关注和了解情况、考生本科阶段的专业背景、本科阶段参与的各类科技活动以及获得过的各种奖励、考生的行为举止、特点特长、综合印象等。</p>
                  </blockquote>
                  <p>看完之后，心中生出淡淡的忧伤，上机考试竟然是C语言，上机题目估计和ACM题目差不多，接下来要重拾C语言了。 另外，对于英语，也是比较看重的，该下点功夫学习英语了，本来英语不算太差，不过也毕竟有一年多没系统学习英语了，希望这几个月可以有些提高。 还有很重要的就是联系北航的导师，如果小伙伴们知道有优秀的导师，可以推荐给我，感激不尽~ 加油吧，崔庆才，为了将来的辉煌！拼一把又何妨！</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-16 22:46:00" itemprop="dateCreated datePublished" datetime="2015-03-16T22:46:00+08:00">2015-03-16</time>
                </span>
                <span id="/1458.html" class="post-meta-item leancloud_visitors" data-flag-title="开始备战了" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>806</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1444.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> JavaScript <i class="label-arrow"></i>
                  </a>
                  <a href="/1444.html" class="post-title-link" itemprop="url">JavaScript高级用法五之常用对象</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>原创内容，个人学习记录，部分API来自W3C，本篇主要介绍了JavaScript中常见的内置对象及其相关用法。</p>
                  <h2 id="Date"><a href="#Date" class="headerlink" title="Date"></a>Date</h2>
                  <p>日期对象，它没有专有属性，有一系列相关方法。</p>
                  <h3 id="1-三种创建方式"><a href="#1-三种创建方式" class="headerlink" title="1.三种创建方式"></a>1.三种创建方式</h3>
                  <figure class="highlight reasonml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">date = <span class="keyword">new</span> <span class="constructor">Date()</span>;&amp;nbsp;                                <span class="comment">//直接创建</span></span><br><span class="line">date = <span class="keyword">new</span> <span class="constructor">Date(<span class="params">val</span>)</span>;                              <span class="comment">//指定日期创建</span></span><br><span class="line">date = <span class="keyword">new</span> <span class="constructor">Date(Y,<span class="params">m</span>,<span class="params">d</span>[,<span class="params">h</span>[,<span class="params">min</span>[,<span class="params">second</span>[,<span class="params">ms</span>]]]])</span>     <span class="comment">//传入具体时间创建</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="2-API"><a href="#2-API" class="headerlink" title="2.API"></a>2.API</h3>
                  <p>方法</p>
                  <p>描述</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_Date.asp" target="_blank" rel="noopener">Date()</a></p>
                  <p>返回当日的日期和时间。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getDate.asp" target="_blank" rel="noopener">getDate()</a></p>
                  <p>从 Date 对象返回一个月中的某一天 (1 ~ 31)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getDay.asp" target="_blank" rel="noopener">getDay()</a></p>
                  <p>从 Date 对象返回一周中的某一天 (0 ~ 6)。注：0-6分别表示星期天-星期六。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getMonth.asp" target="_blank" rel="noopener">getMonth()</a></p>
                  <p>从 Date 对象返回月份 (0 ~ 11)。注：0-11分别表示1-12月份，其值总是比实际月份小1。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getFullYear.asp" target="_blank" rel="noopener">getFullYear()</a></p>
                  <p>从 Date 对象以四位数字返回年份。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getYear.asp" target="_blank" rel="noopener">getYear()</a></p>
                  <p>请使用 getFullYear() 方法代替。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getHours.asp" target="_blank" rel="noopener">getHours()</a></p>
                  <p>返回 Date 对象的小时 (0 ~ 23)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getMinutes.asp" target="_blank" rel="noopener">getMinutes()</a></p>
                  <p>返回 Date 对象的分钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getSeconds.asp" target="_blank" rel="noopener">getSeconds()</a></p>
                  <p>返回 Date 对象的秒数 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getMilliseconds.asp" target="_blank" rel="noopener">getMilliseconds()</a></p>
                  <p>返回 Date 对象的毫秒(0 ~ 999)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getTime.asp" target="_blank" rel="noopener">getTime()</a></p>
                  <p>返回 1970 年 1 月 1 日至今的毫秒数。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getTimezoneOffset.asp" target="_blank" rel="noopener">getTimezoneOffset()</a></p>
                  <p>返回本地时间与格林威治标准时间 (GMT) 的分钟差。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCDate.asp" target="_blank" rel="noopener">getUTCDate()</a></p>
                  <p>根据世界时从 Date 对象返回月中的一天 (1 ~ 31)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCDay.asp" target="_blank" rel="noopener">getUTCDay()</a></p>
                  <p>根据世界时从 Date 对象返回周中的一天 (0 ~ 6)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCMonth.asp" target="_blank" rel="noopener">getUTCMonth()</a></p>
                  <p>根据世界时从 Date 对象返回月份 (0 ~ 11)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCFullYear.asp" target="_blank" rel="noopener">getUTCFullYear()</a></p>
                  <p>根据世界时从 Date 对象返回四位数的年份。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCHours.asp" target="_blank" rel="noopener">getUTCHours()</a></p>
                  <p>根据世界时返回 Date 对象的小时 (0 ~ 23)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCMinutes.asp" target="_blank" rel="noopener">getUTCMinutes()</a></p>
                  <p>根据世界时返回 Date 对象的分钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCSeconds.asp" target="_blank" rel="noopener">getUTCSeconds()</a></p>
                  <p>根据世界时返回 Date 对象的秒钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_getUTCMilliseconds.asp" target="_blank" rel="noopener">getUTCMilliseconds()</a></p>
                  <p>根据世界时返回 Date 对象的毫秒(0 ~ 999)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_parse.asp" target="_blank" rel="noopener">parse()</a></p>
                  <p>返回1970年1月1日午夜到指定日期（字符串）的毫秒数。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setDate.asp" target="_blank" rel="noopener">setDate()</a></p>
                  <p>设置 Date 对象中月的某一天 (1 ~ 31)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setMonth.asp" target="_blank" rel="noopener">setMonth()</a></p>
                  <p>设置 Date 对象中月份 (0 ~ 11)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setFullYear.asp" target="_blank" rel="noopener">setFullYear()</a></p>
                  <p>设置 Date 对象中的年份（四位数字）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setYear.asp" target="_blank" rel="noopener">setYear()</a></p>
                  <p>请使用 setFullYear() 方法代替。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setHours.asp" target="_blank" rel="noopener">setHours()</a></p>
                  <p>设置 Date 对象中的小时 (0 ~ 23)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setMinutes.asp" target="_blank" rel="noopener">setMinutes()</a></p>
                  <p>设置 Date 对象中的分钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setSeconds.asp" target="_blank" rel="noopener">setSeconds()</a></p>
                  <p>设置 Date 对象中的秒钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setMilliseconds.asp" target="_blank" rel="noopener">setMilliseconds()</a></p>
                  <p>设置 Date 对象中的毫秒 (0 ~ 999)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setTime.asp" target="_blank" rel="noopener">setTime()</a></p>
                  <p>以毫秒设置 Date 对象。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setUTCDate.asp" target="_blank" rel="noopener">setUTCDate()</a></p>
                  <p>根据世界时设置 Date 对象中月份的一天 (1 ~ 31)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setUTCMonth.asp" target="_blank" rel="noopener">setUTCMonth()</a></p>
                  <p>根据世界时设置 Date 对象中的月份 (0 ~ 11)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setUTCFullYear.asp" target="_blank" rel="noopener">setUTCFullYear()</a></p>
                  <p>根据世界时设置 Date 对象中的年份（四位数字）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setutchours.asp" target="_blank" rel="noopener">setUTCHours()</a></p>
                  <p>根据世界时设置 Date 对象中的小时 (0 ~ 23)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setUTCMinutes.asp" target="_blank" rel="noopener">setUTCMinutes()</a></p>
                  <p>根据世界时设置 Date 对象中的分钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setUTCSeconds.asp" target="_blank" rel="noopener">setUTCSeconds()</a></p>
                  <p>根据世界时设置 Date 对象中的秒钟 (0 ~ 59)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_setUTCMilliseconds.asp" target="_blank" rel="noopener">setUTCMilliseconds()</a></p>
                  <p>根据世界时设置 Date 对象中的毫秒 (0 ~ 999)。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_tosource_boolean.asp" target="_blank" rel="noopener">toSource()</a></p>
                  <p>返回该对象的源代码。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toString_date.asp" target="_blank" rel="noopener">toString()</a></p>
                  <p>把 Date 对象转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toTimeString.asp" target="_blank" rel="noopener">toTimeString()</a></p>
                  <p>把 Date 对象的时间部分转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toDateString.asp" target="_blank" rel="noopener">toDateString()</a></p>
                  <p>把 Date 对象的日期部分转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toGMTString.asp" target="_blank" rel="noopener">toGMTString()</a></p>
                  <p>请使用 toUTCString() 方法代替。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toUTCString.asp" target="_blank" rel="noopener">toUTCString()</a></p>
                  <p>根据世界时，把 Date 对象转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLocaleString.asp" target="_blank" rel="noopener">toLocaleString()</a></p>
                  <p>根据本地时间格式，把 Date 对象转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLocaleTimeString.asp" target="_blank" rel="noopener">toLocaleTimeString()</a></p>
                  <p>根据本地时间格式，把 Date 对象的时间部分转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLocaleDateString.asp" target="_blank" rel="noopener">toLocaleDateString()</a></p>
                  <p>根据本地时间格式，把 Date 对象的日期部分转换为字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_utc.asp" target="_blank" rel="noopener">UTC()</a></p>
                  <p>根据世界时返回 1970 年 1 月 1 日 到指定日期的毫秒数。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_valueOf_date.asp" target="_blank" rel="noopener">valueOf()</a></p>
                  <p>返回 Date 对象的原始值。</p>
                  <h3 id="3-Demo"><a href="#3-Demo" class="headerlink" title="3.Demo"></a>3.Demo</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">date = <span class="keyword">new</span> <span class="built_in">Date</span>();</span></span><br><span class="line">date.setMonth(10)</span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(date.toDateString()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(date.toTimeString()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(date.toLocaleDateString()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(date.toLocaleTimeString()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">Mon Nov <span class="number">16</span> <span class="number">2015</span></span><br><span class="line"><span class="number">20</span>:<span class="number">06</span>:<span class="number">14</span> GMT+<span class="number">0800</span> (中国标准时间)</span><br><span class="line"><span class="number">2015</span>/<span class="number">11</span>/<span class="number">16</span></span><br><span class="line">下午<span class="number">8</span>:<span class="number">06</span>:<span class="number">14</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="Math"><a href="#Math" class="headerlink" title="Math"></a>Math</h2>
                  <h3 id="1-属性"><a href="#1-属性" class="headerlink" title="1.属性"></a>1.属性</h3>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_e.asp" target="_blank" rel="noopener">E</a></p>
                  <p>返回算术常量 e，即自然对数的底数（约等于2.718）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_ln2.asp" target="_blank" rel="noopener">LN2</a></p>
                  <p>返回 2 的自然对数（约等于0.693）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_ln10.asp" target="_blank" rel="noopener">LN10</a></p>
                  <p>返回 10 的自然对数（约等于2.302）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_log2e.asp" target="_blank" rel="noopener">LOG2E</a></p>
                  <p>返回以 2 为底的 e 的对数（约等于 1.414）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_log10e.asp" target="_blank" rel="noopener">LOG10E</a></p>
                  <p>返回以 10 为底的 e 的对数（约等于0.434）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_pi.asp" target="_blank" rel="noopener">PI</a></p>
                  <p>返回圆周率（约等于3.14159）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sqrt1_2.asp" target="_blank" rel="noopener">SQRT1_2</a></p>
                  <p>返回返回 2 的平方根的倒数（约等于 0.707）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sqrt2.asp" target="_blank" rel="noopener">SQRT2</a></p>
                  <p>返回 2 的平方根（约等于 1.414）。</p>
                  <h3 id="2-API-1"><a href="#2-API-1" class="headerlink" title="2.API"></a>2.API</h3>
                  <p>方法</p>
                  <p>描述</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_abs.asp" target="_blank" rel="noopener">abs(x)</a></p>
                  <p>返回数的绝对值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_acos.asp" target="_blank" rel="noopener">acos(x)</a></p>
                  <p>返回数的反余弦值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_asin.asp" target="_blank" rel="noopener">asin(x)</a></p>
                  <p>返回数的反正弦值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_atan.asp" target="_blank" rel="noopener">atan(x)</a></p>
                  <p>以介于 -PI/2 与 PI/2 弧度之间的数值来返回 x 的反正切值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_atan2.asp" target="_blank" rel="noopener">atan2(y,x)</a></p>
                  <p>返回从 x 轴到点 (x,y) 的角度（介于 -PI/2 与 PI/2 弧度之间）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_ceil.asp" target="_blank" rel="noopener">ceil(x)</a></p>
                  <p>对数进行上舍入。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_cos.asp" target="_blank" rel="noopener">cos(x)</a></p>
                  <p>返回数的余弦。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_exp.asp" target="_blank" rel="noopener">exp(x)</a></p>
                  <p>返回 e 的指数。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_floor.asp" target="_blank" rel="noopener">floor(x)</a></p>
                  <p>对数进行下舍入。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_log.asp" target="_blank" rel="noopener">log(x)</a></p>
                  <p>返回数的自然对数（底为e）。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_max.asp" target="_blank" rel="noopener">max(x,y)</a></p>
                  <p>返回 x 和 y 中的最高值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_min.asp" target="_blank" rel="noopener">min(x,y)</a></p>
                  <p>返回 x 和 y 中的最低值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_pow.asp" target="_blank" rel="noopener">pow(x,y)</a></p>
                  <p>返回 x 的 y 次幂。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_random.asp" target="_blank" rel="noopener">random()</a></p>
                  <p>返回 0 ~ 1 之间的随机数。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_round.asp" target="_blank" rel="noopener">round(x)</a></p>
                  <p>把数四舍五入为最接近的整数。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sin.asp" target="_blank" rel="noopener">sin(x)</a></p>
                  <p>返回数的正弦。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sqrt.asp" target="_blank" rel="noopener">sqrt(x)</a></p>
                  <p>返回数的平方根。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_tan.asp" target="_blank" rel="noopener">tan(x)</a></p>
                  <p>返回角的正切。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_tosource_math.asp" target="_blank" rel="noopener">toSource()</a></p>
                  <p>返回该对象的源代码。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_valueof_math.asp" target="_blank" rel="noopener">valueOf()</a></p>
                  <p>返回 Math 对象的原始值。</p>
                  <h3 id="3-Demo-1"><a href="#3-Demo-1" class="headerlink" title="3.Demo"></a>3.Demo</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(<span class="built_in">Math</span>.E+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(<span class="built_in">Math</span>.ceil(<span class="number">0.6</span>)+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(<span class="built_in">Math</span>.max(<span class="number">5</span>,<span class="number">7</span>) + <span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(<span class="built_in">Math</span>.min(<span class="number">-3</span>,<span class="number">5</span>) + <span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(<span class="built_in">Math</span>.random()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(<span class="built_in">Math</span>.round(<span class="number">0.49</span>)+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">2.718281828459045</span></span><br><span class="line"><span class="number">1</span></span><br><span class="line"><span class="number">7</span></span><br><span class="line"><span class="number">-3</span></span><br><span class="line"><span class="number">0.6166561744175851</span></span><br><span class="line"><span class="number">0</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="String"><a href="#String" class="headerlink" title="String"></a>String</h2>
                  <h3 id="1-属性-1"><a href="#1-属性-1" class="headerlink" title="1.属性"></a>1.属性</h3>
                  <p>constructor</p>
                  <p>对创建该对象的函数的引用</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_length_string.asp" target="_blank" rel="noopener">length</a></p>
                  <p>字符串的长度</p>
                  <p>prototype</p>
                  <p>允许您向对象添加属性和方法</p>
                  <h3 id="2-方法"><a href="#2-方法" class="headerlink" title="2.方法"></a>2.方法</h3>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_anchor.asp" target="_blank" rel="noopener">anchor()</a></p>
                  <p>创建 HTML 锚。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_big.asp" target="_blank" rel="noopener">big()</a></p>
                  <p>用大号字体显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_blink.asp" target="_blank" rel="noopener">blink()</a></p>
                  <p>显示闪动字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_bold.asp" target="_blank" rel="noopener">bold()</a></p>
                  <p>使用粗体显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_charAt.asp" target="_blank" rel="noopener">charAt()</a></p>
                  <p>返回在指定位置的字符。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_charCodeAt.asp" target="_blank" rel="noopener">charCodeAt()</a></p>
                  <p>返回在指定的位置的字符的 Unicode 编码。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_concat_string.asp" target="_blank" rel="noopener">concat()</a></p>
                  <p>连接字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_fixed.asp" target="_blank" rel="noopener">fixed()</a></p>
                  <p>以打字机文本显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_fontcolor.asp" target="_blank" rel="noopener">fontcolor()</a></p>
                  <p>使用指定的颜色来显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_fontsize.asp" target="_blank" rel="noopener">fontsize()</a></p>
                  <p>使用指定的尺寸来显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_fromCharCode.asp" target="_blank" rel="noopener">fromCharCode()</a></p>
                  <p>从字符编码创建一个字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_indexOf.asp" target="_blank" rel="noopener">indexOf()</a></p>
                  <p>检索字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_italics.asp" target="_blank" rel="noopener">italics()</a></p>
                  <p>使用斜体显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_lastIndexOf.asp" target="_blank" rel="noopener">lastIndexOf()</a></p>
                  <p>从后向前搜索字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_link.asp" target="_blank" rel="noopener">link()</a></p>
                  <p>将字符串显示为链接。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_localeCompare.asp" target="_blank" rel="noopener">localeCompare()</a></p>
                  <p>用本地特定的顺序来比较两个字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_match.asp" target="_blank" rel="noopener">match()</a></p>
                  <p>找到一个或多个正则表达式的匹配。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_replace.asp" target="_blank" rel="noopener">replace()</a></p>
                  <p>替换与正则表达式匹配的子串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_search.asp" target="_blank" rel="noopener">search()</a></p>
                  <p>检索与正则表达式相匹配的值。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_slice_string.asp" target="_blank" rel="noopener">slice()</a></p>
                  <p>提取字符串的片断，并在新的字符串中返回被提取的部分。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_small.asp" target="_blank" rel="noopener">small()</a></p>
                  <p>使用小字号来显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_split.asp" target="_blank" rel="noopener">split()</a></p>
                  <p>把字符串分割为字符串数组。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_strike.asp" target="_blank" rel="noopener">strike()</a></p>
                  <p>使用删除线来显示字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sub.asp" target="_blank" rel="noopener">sub()</a></p>
                  <p>把字符串显示为下标。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_substr.asp" target="_blank" rel="noopener">substr()</a></p>
                  <p>从起始索引号提取字符串中指定数目的字符。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_substring.asp" target="_blank" rel="noopener">substring()</a></p>
                  <p>提取字符串中两个指定的索引号之间的字符。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sup.asp" target="_blank" rel="noopener">sup()</a></p>
                  <p>把字符串显示为上标。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLocaleLowerCase.asp" target="_blank" rel="noopener">toLocaleLowerCase()</a></p>
                  <p>把字符串转换为小写。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLocaleUpperCase.asp" target="_blank" rel="noopener">toLocaleUpperCase()</a></p>
                  <p>把字符串转换为大写。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLowerCase.asp" target="_blank" rel="noopener">toLowerCase()</a></p>
                  <p>把字符串转换为小写。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toUpperCase.asp" target="_blank" rel="noopener">toUpperCase()</a></p>
                  <p>把字符串转换为大写。</p>
                  <p>toSource()</p>
                  <p>代表对象的源代码。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toString_string.asp" target="_blank" rel="noopener">toString()</a></p>
                  <p>返回字符串。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_valueOf_string.asp" target="_blank" rel="noopener">valueOf()</a></p>
                  <p>返回某个字符串对象的原始值。</p>
                  <h3 id="3-Demo-2"><a href="#3-Demo-2" class="headerlink" title="3.Demo"></a>3.Demo</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="actionscript"><span class="keyword">var</span> txt=<span class="string">"Hello world!"</span></span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(txt.anchor(<span class="string">"myanchor"</span>)+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(txt.big()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(txt.blink()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(txt.small()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(txt.sup()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="actionscript"><span class="keyword">var</span> str1=<span class="string">"Hello "</span></span></span><br><span class="line"><span class="actionscript"><span class="keyword">var</span> str2=<span class="string">"world!"</span></span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(str1.concat(str2))</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight erlang-repl">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"> Hello world!</span><br><span class="line">Hello world!</span><br><span class="line">Hello world!</span><br><span class="line">Hello world!</span><br><span class="line">Hello world!</span><br><span class="line">Hello world!</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h2 id="Array"><a href="#Array" class="headerlink" title="Array"></a>Array</h2>
                  <h3 id="1-创建方式"><a href="#1-创建方式" class="headerlink" title="1.创建方式"></a>1.创建方式</h3>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">var a = new Array();</span><br><span class="line">var a = new Array(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>);</span><br><span class="line">var a = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>];</span><br><span class="line">var a = new Array(<span class="number">3</span>);</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="2-属性"><a href="#2-属性" class="headerlink" title="2.属性"></a>2.属性</h3>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_constructor_array.asp" target="_blank" rel="noopener">constructor</a></p>
                  <p>返回对创建此对象的数组函数的引用。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_length_array.asp" target="_blank" rel="noopener">length</a></p>
                  <p>设置或返回数组中元素的数目。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_prototype_array.asp" target="_blank" rel="noopener">prototype</a></p>
                  <p>使您有能力向对象添加属性和方法。</p>
                  <h3 id="3-API"><a href="#3-API" class="headerlink" title="3.API"></a>3.API</h3>
                  <p>JavaScript Array 对象</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_concat_array.asp" target="_blank" rel="noopener">concat()</a></p>
                  <p>连接两个或更多的数组，并返回结果。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_join.asp" target="_blank" rel="noopener">join()</a></p>
                  <p>把数组的所有元素放入一个字符串。元素通过指定的分隔符进行分隔。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_pop.asp" target="_blank" rel="noopener">pop()</a></p>
                  <p>删除并返回数组的最后一个元素</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_push.asp" target="_blank" rel="noopener">push()</a></p>
                  <p>向数组的末尾添加一个或更多元素，并返回新的长度。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_reverse.asp" target="_blank" rel="noopener">reverse()</a></p>
                  <p>颠倒数组中元素的顺序。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_shift.asp" target="_blank" rel="noopener">shift()</a></p>
                  <p>删除并返回数组的第一个元素</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_slice_array.asp" target="_blank" rel="noopener">slice()</a></p>
                  <p>从某个已有的数组返回选定的元素</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_sort.asp" target="_blank" rel="noopener">sort()</a></p>
                  <p>对数组的元素进行排序</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_splice.asp" target="_blank" rel="noopener">splice()</a></p>
                  <p>删除元素，并向数组添加新元素。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_tosource_array.asp" target="_blank" rel="noopener">toSource()</a></p>
                  <p>返回该对象的源代码。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toString_array.asp" target="_blank" rel="noopener">toString()</a></p>
                  <p>把数组转换为字符串，并返回结果。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_toLocaleString_array.asp" target="_blank" rel="noopener">toLocaleString()</a></p>
                  <p>把数组转换为本地数组，并返回结果。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_unshift.asp" target="_blank" rel="noopener">unshift()</a></p>
                  <p>向数组的开头添加一个或更多元素，并返回新的长度。</p>
                  <p><a href="http://www.w3school.com.cn/jsref/jsref_valueof_array.asp" target="_blank" rel="noopener">valueOf()</a></p>
                  <p>返回数组对象的原始值</p>
                  <h3 id="3-Demo-3"><a href="#3-Demo-3" class="headerlink" title="3.Demo"></a>3.Demo</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript"><span class="keyword">var</span> arr1 = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(arr1.concat([<span class="number">6</span>,<span class="number">7</span>])+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="keyword">var</span> arr2 = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">2</span>);</span></span><br><span class="line"><span class="actionscript">arr2[<span class="number">0</span>] = <span class="string">'Hello'</span>;</span></span><br><span class="line"><span class="actionscript">arr2[<span class="number">1</span>] = <span class="string">'World'</span>;</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(arr2.join()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(arr2.pop()+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="keyword">var</span> arr = <span class="keyword">new</span> <span class="built_in">Array</span>(<span class="number">6</span>);</span></span><br><span class="line"><span class="actionscript">arr[<span class="number">0</span>] = <span class="string">"George"</span>;</span></span><br><span class="line"><span class="actionscript">arr[<span class="number">1</span>] = <span class="string">"John"</span>;</span></span><br><span class="line"><span class="actionscript">arr[<span class="number">2</span>] = <span class="string">"Thomas"</span>;</span></span><br><span class="line"><span class="actionscript">arr[<span class="number">3</span>] = <span class="string">"James"</span>;</span></span><br><span class="line"><span class="actionscript">arr[<span class="number">4</span>] = <span class="string">"Adrew"</span>;</span></span><br><span class="line"><span class="actionscript">arr[<span class="number">5</span>] = <span class="string">"Martin"</span>;</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(arr + <span class="string">"&lt;br /&gt;"</span>);</span></span><br><span class="line"><span class="actionscript">arr.splice(<span class="number">2</span>,<span class="number">3</span>,<span class="string">"William"</span>);  <span class="comment">//删除index2开始的3个元素</span></span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(arr+<span class="string">"&lt;br&gt;"</span>);</span></span><br><span class="line"><span class="javascript"><span class="built_in">document</span>.write(arr.valueOf());</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">6</span>,<span class="number">7</span></span><br><span class="line">Hello,World</span><br><span class="line">World</span><br><span class="line">George,John,Thomas,James,Adrew,Martin</span><br><span class="line">George,John,William,Martin</span><br><span class="line">George,John,William,Martin</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>s</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-16 19:56:28" itemprop="dateCreated datePublished" datetime="2015-03-16T19:56:28+08:00">2015-03-16</time>
                </span>
                <span id="/1444.html" class="post-meta-item leancloud_visitors" data-flag-title="JavaScript高级用法五之常用对象" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>5.9k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>5 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1415.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> Other <i class="label-arrow"></i>
                  </a>
                  <a href="/1415.html" class="post-title-link" itemprop="url">PS抠头发丝详细教程</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>博主原创内容。 在PS里，对于抠图，比较有技术含量的便是抠头发丝了，下面为大家带来一个比较详细的抠头发丝的教程。</p>
                  <h2 id="素材准备"><a href="#素材准备" class="headerlink" title="素材准备"></a>素材准备</h2>
                  <p>在这里我们用这张图片作为抠图素材，下面让我们一步步来演示抠图的过程，并为之更换背景。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/3f5733ef0e9cd8dafeb910d866284128.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/3f5733ef0e9cd8dafeb910d866284128.jpg" alt="3f5733ef0e9cd8dafeb910d866284128"></a></p>
                  <h2 id="抠图过程"><a href="#抠图过程" class="headerlink" title="抠图过程"></a>抠图过程</h2>
                  <h3 id="1-打开素材"><a href="#1-打开素材" class="headerlink" title="1.打开素材"></a>1.打开素材</h3>
                  <p>第一步，当然是用PS打开这张图片素材啦。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150314235120.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150314235120.jpg" alt="20150314235120"></a></p>
                  <h3 id="2-复制通道"><a href="#2-复制通道" class="headerlink" title="2.复制通道"></a>2.复制通道</h3>
                  <p>打开通道选项卡，按每个通道的前面的小眼睛，让红绿蓝通道依次显示，观察哪一个通道明暗对比更加明显，在这里，我们发现蓝色通道的明暗对比更加明显，那我们就右键复制，建立蓝色通道的一个副本，如图所示。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150314235402.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150314235402.jpg" alt="20150314235402"></a></p>
                  <h3 id="３-调整色阶"><a href="#３-调整色阶" class="headerlink" title="３.调整色阶"></a>３.调整色阶</h3>
                  <p>打开图像－调整－色阶，将低色阶调高，高色阶调低，让图片的明暗对比更加明显，点击确定。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/未标题-1.png" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/未标题-1.png" alt="未标题-1"></a> <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/0150314235948.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/0150314235948.jpg" alt="0150314235948"></a> </p>
                  <h3 id="４-减淡加深"><a href="#４-减淡加深" class="headerlink" title="４.减淡加深"></a>４.减淡加深</h3>
                  <p>切换至减淡或加深工具，首先我们切换到减淡工具，范围选择高光，直接对图片的亮白部分进行涂抹，这时我们会发现比较亮的部分都被减淡为白色，如图所示。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000249.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000249.jpg" alt="20150315000249"></a> 然后切换到加深工具，范围选择阴影，直接涂抹人物，将人物全部涂抹成黑色，如图所示 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000438.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000438.jpg" alt="20150315000438"></a> <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000519.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000519.jpg" alt="20150315000519"></a> <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000617.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000617.jpg" alt="20150315000617"></a> </p>
                  <h3 id="５-画笔修补"><a href="#５-画笔修补" class="headerlink" title="５.画笔修补"></a>５.画笔修补</h3>
                  <p>这时我们会发现几乎所有的人物都已经变成了黑色，不过还有小瑕疵，有一小部分还没有变成黑色，没关系，切换到画笔工具，颜色选择黑色，让我们把没有变成黑色的部分进行填充。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000838.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315000838.jpg" alt="20150315000838"></a> <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001006.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001006.jpg" alt="20150315001006"></a></p>
                  <h3 id="６-反向检查"><a href="#６-反向检查" class="headerlink" title="６.反向检查"></a>６.反向检查</h3>
                  <p>按Ctrl+I，将图片切换为反向，将黑白部分没有填充好的地方重新用画笔工具填充一下，保证做到黑白分明。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001156.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001156.jpg" alt="20150315001156"></a></p>
                  <h3 id="7-抠出人物"><a href="#7-抠出人物" class="headerlink" title="7.抠出人物"></a>7.抠出人物</h3>
                  <p>按住Ctrl键，鼠标移至图层的小图标处点击，即图中红色框处的区域，点击一下，即可选中人物的轮廓。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001334.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001334.jpg" alt="20150315001334"></a> 将图层的RGB通道全部复原，切换至图层面板 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001556.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001556.jpg" alt="20150315001556"></a> <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001638.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315001638.jpg" alt="20150315001638"></a> 按Ctrl+J，复制选区中的内容到新的图层，这时我们会发现新建了一个图层，它的背景是透明的。(P.S.按第一次不生效可以尝试按第二次，我这边出现了一个副本，然后便是透明背景的图片) <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315002534.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315002534.jpg" alt="20150315002534"></a></p>
                  <h3 id="8-更换背景"><a href="#8-更换背景" class="headerlink" title="8.更换背景"></a>8.更换背景</h3>
                  <p>我们在该图层下面新建一个图层，填充为自己想要的颜色，看一下效果，在这里我设置了灰白渐变效果。 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315002659.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315002659.jpg" alt="20150315002659"></a></p>
                  <h3 id="9-去除白边"><a href="#9-去除白边" class="headerlink" title="9.去除白边"></a>9.去除白边</h3>
                  <p>选中人物图层，选择图层-修边-移除白色杂边，即可去除边缘的杂边干扰 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315004324.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150315004324.jpg" alt="20150315004324"></a> 这样一来，抠头发丝的完整过程就结束啦。</p>
                  <h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2>
                  <p>以上便是抠头发丝的全部过程，如果做证件照的话，可以尝试一用，希望对大家有帮助</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-15 00:45:48" itemprop="dateCreated datePublished" datetime="2015-03-15T00:45:48+08:00">2015-03-15</time>
                </span>
                <span id="/1415.html" class="post-meta-item leancloud_visitors" data-flag-title="PS抠头发丝详细教程" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>858</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1408.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> HTML <i class="label-arrow"></i>
                  </a>
                  <a href="/1408.html" class="post-title-link" itemprop="url">HTML5实现响应式进度条及分享图标</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>纯原创内容，HTML5实现个人简介界面，响应式布局的进度条以及利用Font-Awesome实现分享图标，完美支持手机端。 已经在博主个人网站应用 <a href="http://cuiqingcai.com/about">进入页面</a></p>
                  <h2 id="截图"><a href="#截图" class="headerlink" title="截图"></a>截图</h2>
                  <h3 id="1-电脑端"><a href="#1-电脑端" class="headerlink" title="1.电脑端"></a>1.电脑端</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313145032.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313145032.jpg" alt="20150313145032"></a> </p>
                  <h3 id="2-手机端"><a href="#2-手机端" class="headerlink" title="2.手机端"></a>2.手机端</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313145528.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313145528.jpg" alt="20150313145528"></a> <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313145629.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313145629.jpg" alt="20150313145629"></a> </p>
                  <h2 id="在线演示"><a href="#在线演示" class="headerlink" title="在线演示"></a>在线演示</h2>
                  <p><a href="http://res.cuiqingcai.com/aboutme/" target="_blank" rel="noopener">在线演示</a></p>
                  <h2 id="源码下载"><a href="#源码下载" class="headerlink" title="源码下载"></a>源码下载</h2>
                  <p><a href="https://github.com/cqcre/aboutme" target="_blank" rel="noopener">源码下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-13 15:16:26" itemprop="dateCreated datePublished" datetime="2015-03-13T15:16:26+08:00">2015-03-13</time>
                </span>
                <span id="/1408.html" class="post-meta-item leancloud_visitors" data-flag-title="HTML5实现响应式进度条及分享图标" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>105</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1401.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> HTML <i class="label-arrow"></i>
                  </a>
                  <a href="/1401.html" class="post-title-link" itemprop="url">HTML5实现2048网页游戏</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>改编内容，HTML5实现2048游戏的开发，添加了小屏幕适配，支持手机端触控。</p>
                  <h2 id="截图"><a href="#截图" class="headerlink" title="截图"></a>截图</h2>
                  <h3 id="1-电脑端"><a href="#1-电脑端" class="headerlink" title="1.电脑端"></a>1.电脑端</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313140648.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313140648.jpg" alt="20150313140648"></a></p>
                  <h3 id="2-平板端"><a href="#2-平板端" class="headerlink" title="2.平板端"></a>2.平板端</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313142906.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313142906.jpg" alt="20150313142906"></a></p>
                  <h3 id="3-手机端"><a href="#3-手机端" class="headerlink" title="3.手机端"></a>3.手机端</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313143200.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313143200.jpg" alt="20150313143200"></a></p>
                  <h2 id="在线演示"><a href="#在线演示" class="headerlink" title="在线演示"></a>在线演示</h2>
                  <p><a href="http://res.cuiqingcai.com/2048/" target="_blank" rel="noopener">在线演示</a></p>
                  <h2 id="源码下载"><a href="#源码下载" class="headerlink" title="源码下载"></a>源码下载</h2>
                  <p><a href="https://github.com/cqcre" target="_blank" rel="noopener">源码下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-13 14:35:13" itemprop="dateCreated datePublished" datetime="2015-03-13T14:35:13+08:00">2015-03-13</time>
                </span>
                <span id="/1401.html" class="post-meta-item leancloud_visitors" data-flag-title="HTML5实现2048网页游戏" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>74</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1387.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> HTML <i class="label-arrow"></i>
                  </a>
                  <a href="/1387.html" class="post-title-link" itemprop="url">纯CSS3实现微信二维码动态呈现</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="综述"><a href="#综述" class="headerlink" title="综述"></a>综述</h2>
                  <p>原创内容，纯 CSS3 实现微信扫一扫的功能，页面一共五个二维码，鼠标移上二维码会自动放大，同时支持响应式布局，整体会根据页面响应式缩放。 在我的个人网站赞助页面即存在这个 DEMO <a href="http://cuiqingcai.com/donate">进入页面</a></p>
                  <h2 id="截图"><a href="#截图" class="headerlink" title="截图"></a>截图</h2>
                  <h3 id="1-正常情况，大屏幕"><a href="#1-正常情况，大屏幕" class="headerlink" title="1.正常情况，大屏幕"></a>1.正常情况，大屏幕</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150312235820.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150312235820.jpg" alt="20150312235820"></a></p>
                  <h3 id="2-鼠标移上，大屏幕"><a href="#2-鼠标移上，大屏幕" class="headerlink" title="2.鼠标移上，大屏幕"></a>2.鼠标移上，大屏幕</h3>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150312235953.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150312235953.jpg" alt="20150312235953"></a> 3.小屏幕 <a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313000056.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/20150313000056.jpg" alt="20150313000056"></a></p>
                  <h2 id="在线演示"><a href="#在线演示" class="headerlink" title="在线演示"></a>在线演示</h2>
                  <p><a href="http://res.cuiqingcai.com/wechatpay/" target="_blank" rel="noopener">在线演示</a></p>
                  <h2 id="源码下载"><a href="#源码下载" class="headerlink" title="源码下载"></a>源码下载</h2>
                  <p><a href="https://github.com/cqcre/WechatPay" target="_blank" rel="noopener">源码下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-13 00:05:17" itemprop="dateCreated datePublished" datetime="2015-03-13T00:05:17+08:00">2015-03-13</time>
                </span>
                <span id="/1387.html" class="post-meta-item leancloud_visitors" data-flag-title="纯CSS3实现微信二维码动态呈现" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>136</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1377.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> JavaScript <i class="label-arrow"></i>
                  </a>
                  <a href="/1377.html" class="post-title-link" itemprop="url">JavaScript视频学习教程</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="关于JavaScript"><a href="#关于JavaScript" class="headerlink" title="关于JavaScript"></a>关于JavaScript</h2>
                  <p> <strong>JavaScript</strong>，一种直译式脚本语言，是一种动态类型、弱类型、基于原型的语言，内置支持类。它的解释器被称为JavaScript引擎，为浏览器的一部分，广泛用于客户端的脚本语言，最早是在HTML网页上使用，用来给HTML网页增加动态功能。然而现在JavaScript也可被用于网络服务器，如Node.js。 不同于服务器端脚本语言，例如PHP与ASP，JavaScript主要被作为客户端脚本语言在用户的浏览器上运行，不需要服务器的支持。所以在早期程序员比较青睐于JavaScript以减少对服务器的负担，而与此同时也带来另一个问题：安全性。而随着服务器的强壮，虽然现在的程序员更喜欢运行于服务端的脚本以保证安全，但JavaScript仍然以其跨平台、容易上手等优势大行其道。同时，有些特殊功能（如AJAX）必须依赖Javascript在客户端进行支持。随着引擎如V8和框架如Node.js的发展，及其事件驱动及异步IO等特性，JavaScript逐渐被用来编写服务器端程序。 视频来源：兄弟连教育 感谢 @<a href="http://weibo.com/lampbrother" target="_blank" rel="noopener">兄弟连教育</a></p>
                  <h2 id="关于兄弟连"><a href="#关于兄弟连" class="headerlink" title="关于兄弟连"></a>关于兄弟连</h2>
                  <p>兄弟连成立于2006年，专注于IT技术培训，是国内最早及最大的PHP/LAMP技术专业培训学校。 兄弟连现已开设PHP/Java/Android/IOS/手游/云计算/UI等多学科，累计培养逾万名学员，2014年学员就业平均起薪高达5500元+。 兄弟连已是第9个年头，这条路虽历尽艰辛，但我们痴心不改。我们就是想让学员们知道：不是所有的培训机构都是骗人的！ 在兄弟连，你可以找到自我、重拾自信；在兄弟连，你会每天渴求成长，学到深夜； 在兄弟连，你把学习当成一种习惯；在兄弟连，你有更多的兄弟姐妹； 在兄弟连，有陪你一起熬夜的老师；在兄弟连，你会被“狠狠”的爱着…… 兄弟连已在北京、上海和广州设立校区，今后几年内将会陆续在成都、西安等地建设校区，每年有数十万名学员受益于兄弟连教育的职业培训、教学视频、网络公开课。</p>
                  <blockquote>
                    <p>兄弟连</p>
                    <p>“我们不仅仅是老师，我们是学员的梦想守护者与职场引路人。” 我们不敢妄言改变中国教育，只是低下头认认真真做教育。兄弟连没有做什么惊天动地的大事，我们就是把别人不愿做的脏活累活做到极致，做教育就是需要这种工匠精神。 在中国，选择职业培训的学生，一定是对自己未来有憧憬、想改变命运的有志青年。主观上有学习的欲望，客观上自控能力差，需要外力协助其改变。 教学靠谱/变态严管/职业素养课我们的核心竞争力。 培训结束会有脱胎换骨的感觉，怕死别来兄弟连！</p>
                  </blockquote>
                  <h2 id="视频下载"><a href="#视频下载" class="headerlink" title="视频下载"></a>视频下载</h2>
                  <p><a href="http://pan.baidu.com/s/1kTzfpht" target="_blank" rel="noopener">视频下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-12 00:27:37" itemprop="dateCreated datePublished" datetime="2015-03-12T00:27:37+08:00">2015-03-12</time>
                </span>
                <span id="/1377.html" class="post-meta-item leancloud_visitors" data-flag-title="JavaScript视频学习教程" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>1.1k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1360.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> 福利专区 <i class="label-arrow"></i>
                  </a>
                  <a href="/1360.html" class="post-title-link" itemprop="url">一步一步学摄影精华视频教程</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="摄影基本原理"><a href="#摄影基本原理" class="headerlink" title="摄影基本原理"></a>摄影基本原理</h2>
                  <p>在摄影中，通常使用照相机或者照相暗盒（Camera obscura）作为照相设备，利用光学胶卷或者数码存储卡作为记录介质。但也有例外，比如曼·雷的实物投影法（rayographs）就是利用影子在相纸上成像，而不需要用到照相机。 多数照相是用一系列的透镜组成的镜头，将光线折射聚焦后在胶片或者CCD光学感应介质，胶片本身也是储存介质，以化学变化储存讯号。而CCD则会将光转换为电子讯号后，以数码存储卡储存。储存的讯号可透过某些方式，还原成光学信息后，用相片或显示器观赏。除了透镜构成的镜头，少数镜头是用反射镜或反射镜搭配透镜所构成。</p>
                  <h2 id="摄影艺术"><a href="#摄影艺术" class="headerlink" title="摄影艺术"></a>摄影艺术</h2>
                  <p>摄影艺术是一门较为年轻的艺术门类，它是紧紧伴随着每个时代高新科技发展而发展着。摄影艺术是一种对现实高度概括；是来源于生活而高于生活的影像工作方式；是一种高贵的雅文化。摄影艺术就是作者的一种表达，正如说话是一种表达、写作是一种表达一样。摄影的表达方式多种多样，可以“风光”、“静物”、“人像”，也可以“纪实”、“民俗”、“观念”，表达方式没有高下之分。</p>
                  <p>摄影技术的学习不仅仅是学习光圈、焦距、曝光、色温、反差、感光度、白平衡之类的技术性知识，也不仅仅是学习构图、造型、色彩、光影等等美学知识，还有学习中外优秀摄影师的作品，看摄影师的画册和论著啦，等等。此外，还要学习一些诸如哲学、人类学、社会学、历史学、艺术史之类似乎与摄影无甚直接关系的学问。</p>
                  <p><a href="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/wallpaper_5255573.jpg" target="_blank" rel="noopener"><img src="http://qiniu.cuiqingcai.com/wp-content/uploads/2015/03/wallpaper_5255573.jpg" alt="wallpaper_5255573"></a></p>
                  <h2 id="视频下载"><a href="#视频下载" class="headerlink" title="视频下载"></a>视频下载</h2>
                  <p><a href="http://pan.baidu.com/s/1bnxtHYv" target="_blank" rel="noopener">视频下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-12 00:10:01" itemprop="dateCreated datePublished" datetime="2015-03-12T00:10:01+08:00">2015-03-12</time>
                </span>
                <span id="/1360.html" class="post-meta-item leancloud_visitors" data-flag-title="一步一步学摄影精华视频教程" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>601</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1350.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> PHP <i class="label-arrow"></i>
                  </a>
                  <a href="/1350.html" class="post-title-link" itemprop="url">ThinkPHP视频学习教程</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="关于PHP"><a href="#关于PHP" class="headerlink" title="关于PHP"></a>关于PHP</h2>
                  <p>PHP（外文名: Hypertext Preprocessor，中文名：“超文本预处理器”）是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点，利于学习，使用广泛，主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比，PHP是将程序嵌入到HTML（标准通用标记语言下的一个应用）文档中去执行，执行效率比完全生成HTML标记的CGI要高许多；PHP还可以执行编译后代码，编译可以达到加密和优化代码运行，使代码运行更快。 在此提供PHP视频教程，视频来源：兄弟连教育</p>
                  <h2 id="关于THINKPHP"><a href="#关于THINKPHP" class="headerlink" title="关于THINKPHP"></a>关于THINKPHP</h2>
                  <pre><code>    ThinkPHP是为了简化企业级应用开发和敏捷WEB应用开发而诞生的。最早诞生于2006年初，2007年元旦正式更名为ThinkPHP，并且遵循Apache2开源协议发布。ThinkPHP从诞生以来一直秉承简洁实用的设计原则，在保持出色的性能和至简的代码的同时，也注重易用性。并且拥有众多原创功能和特性，在社区团队的积极参与下，在易用性、扩展性和性能方面不断优化和改进。

    ThinkPHP是一个快速、兼容而且简单的轻量级国产PHP开发框架，诞生于2006年初，原名FCS，2007年元旦正式更名为ThinkPHP，遵循Apache2开源协议发布，从Struts结构移植过来并做了改进和完善，同时也借鉴了国外很多优秀的框架和模式，使用面向对象的开发结构和MVC模式，融合了Struts的思想和TagLib（标签库）、RoR的ORM映射和ActiveRecord模式。
</code></pre>
                  <p>ThinkPHP可以支持windows/Unix/Liunx等服务器环境，正式版需要PHP5.0以上版本支持，支持MySql、PgSQL、Sqlite以及PDO等多种数据库，ThinkPHP框架本身没有什么特别模块要求，具体的应用系统运行环境要求视开发所涉及的模块。</p>
                  <p>作为一个整体开发解决方案，ThinkPHP能够解决应用开发中的大多数需要，因为其自身包含了底层架构、兼容处理、基类库、数据库访问层、模板引擎、缓存机制、插件机制、角色认证、表单处理等常用的组件，并且对于跨版本、跨平台和跨数据库移植都比较方便。并且每个组件都是精心设计和完善的，应用开发过程仅仅需要关注您的业务逻辑。</p>
                  <h2 id="关于兄弟连"><a href="#关于兄弟连" class="headerlink" title="关于兄弟连"></a>关于兄弟连</h2>
                  <p>兄弟连成立于2006年，专注于IT技术培训，是国内最早及最大的PHP/LAMP技术专业培训学校。 兄弟连现已开设PHP/Java/Android/IOS/手游/云计算/UI等多学科，累计培养逾万名学员，2014年学员就业平均起薪高达5500元+。 兄弟连已是第9个年头，这条路虽历尽艰辛，但我们痴心不改。我们就是想让学员们知道：不是所有的培训机构都是骗人的！ 在兄弟连，你可以找到自我、重拾自信；在兄弟连，你会每天渴求成长，学到深夜； 在兄弟连，你把学习当成一种习惯；在兄弟连，你有更多的兄弟姐妹； 在兄弟连，有陪你一起熬夜的老师；在兄弟连，你会被“狠狠”的爱着…… 兄弟连已在北京、上海和广州设立校区，今后几年内将会陆续在成都、西安等地建设校区，每年有数十万名学员受益于兄弟连教育的职业培训、教学视频、网络公开课。</p>
                  <blockquote>
                    <p>兄弟连</p>
                    <p>“我们不仅仅是老师，我们是学员的梦想守护者与职场引路人。” 我们不敢妄言改变中国教育，只是低下头认认真真做教育。兄弟连没有做什么惊天动地的大事，我们就是把别人不愿做的脏活累活做到极致，做教育就是需要这种工匠精神。 在中国，选择职业培训的学生，一定是对自己未来有憧憬、想改变命运的有志青年。主观上有学习的欲望，客观上自控能力差，需要外力协助其改变。 教学靠谱/变态严管/职业素养课我们的核心竞争力。 培训结束会有脱胎换骨的感觉，怕死别来兄弟连！</p>
                  </blockquote>
                  <p>感谢 <a href="http://weibo.com/lampbrother" target="_blank" rel="noopener">@兄弟连教育</a></p>
                  <blockquote>
                    <p><strong>VERSION：THINKPHP 版本 3.1.2</strong> </p>
                  </blockquote>
                  <p><a href="http://www.lampbrother.net/phptrain/video_13.php" target="_blank" rel="noopener">视频下载</a></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-11 23:54:39" itemprop="dateCreated datePublished" datetime="2015-03-11T23:54:39+08:00">2015-03-11</time>
                </span>
                <span id="/1350.html" class="post-meta-item leancloud_visitors" data-flag-title="ThinkPHP视频学习教程" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>1.6k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>1 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1809.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> Java <i class="label-arrow"></i>
                  </a>
                  <a href="/1809.html" class="post-title-link" itemprop="url">Win7用Eclipse配置JSP开发环境详细教程</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <h2 id="一、安装jdk"><a href="#一、安装jdk" class="headerlink" title="一、安装jdk"></a><strong>一、安装jdk</strong></h2>
                  <h3 id="1）下载jdk1-7"><a href="#1）下载jdk1-7" class="headerlink" title="1）下载jdk1.7"></a>1）下载jdk1.7</h3>
                  <p><a href="http://pan.baidu.com/s/1i3BPXfZ" target="_blank" rel="noopener">下载地址</a> 自己定义一个目录安装，一步步安装下来，我是安装到了D盘，如图所示： <img src="http://img.blog.csdn.net/20140307134338765?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""></p>
                  <h3 id="2）设置环境变量"><a href="#2）设置环境变量" class="headerlink" title="2）设置环境变量"></a>2）设置环境变量</h3>
                  <p>我的电脑右击点属性，再点高级系统设置<img src="http://img.blog.csdn.net/20140307134535000?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 点击环境变量进行环境变量配置,如图所示： <img src="http://img.blog.csdn.net/20140307134833656?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> <strong>配置方法一：</strong> 1）配置时找到系统变量，找到path变量，如果没有则新建。 在变量名填Path，变量值填 D:\jdk1.7\bin;注意要加分号！ 如图所示： <img src="http://img.blog.csdn.net/20140307135858343?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 2）同理，找到变量名classpath，没有就新建一个classpath 变量值填D:\jdk1.7\lib;. <strong>配制方法二：</strong></p>
                  <blockquote>
                    <p>1）新建java_home变量 变量名：java_home 变量值：D:\jdk1.7; 2）变量名：path 变量值：%java_home%\bin; 3）变量名：classpath 变量值：%java_home%\lib;</p>
                  </blockquote>
                  <p>这个是以后配置时直接引用java_home比较方便 这样jdk的安装和环境变量的配置就完成啦！ 测试是否成功：在命令行输入java -version 如果出现下列字符则说明成功 <img src="http://img.blog.csdn.net/20140307140619578?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""></p>
                  <h2 id="二、Eclipse的下载"><a href="#二、Eclipse的下载" class="headerlink" title="二、Eclipse的下载"></a><strong>二、Eclipse的下载</strong></h2>
                  <p>注意：此处提供的3.3版本，若版本太高，没有与Eclipse相对应的lomboz版本则无法配置，目前lomboz最高是3.3版本 <a href="http://pan.baidu.com/s/1dDoX5cd" target="_blank" rel="noopener">下载地址</a> 注意：如果你已经有了3.3版本，那么可以跳过此步。 我新建了一个JspEclipse文件夹，解压到此文件夹如图所示： <img src="http://img.blog.csdn.net/20140307140948171?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 首先进行汉化 <a href="http://pan.baidu.com/s/1i3qlpVB" target="_blank" rel="noopener">语言包下载</a> 下载后新建一个eclipse_plugins文件夹，解压到此文件夹下，创建这个文件夹的目的是把所有下载的插件都保存到这里，便于管理 目录层次如图所示，language下有eclipse，eclipse下有features和plugins文件夹 <img src="http://img.blog.csdn.net/20140307141539359?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 在原先的JspEclipse下的eclipse文件夹下新建一个links文件夹，再新建文本文件，扩展名为link，内容如图所示： <img src="http://img.blog.csdn.net/20140307141957281?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 这样汉化就完成了</p>
                  <h2 id="三、配置lomboz"><a href="#三、配置lomboz" class="headerlink" title="三、配置lomboz"></a><strong>三、配置lomboz</strong></h2>
                  <p><a href="http://pan.baidu.com/s/1eQmTBRO" target="_blank" rel="noopener">下载地址</a> 同样下载解压到原先创建的eclipse_plugins文件夹下，如图所示： <img src="http://img.blog.csdn.net/20140307142231640?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 同上在原先的JspEclipse下的eclipse文件夹下新建一个links文件夹，再新建文本文件，扩展名为link，内容如图所示： <img src="http://img.blog.csdn.net/20140307142453828?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 这样lomboz就配置完成啦，启动一下试试！ <img src="http://img.blog.csdn.net/20140307142646296?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 此处显示中文，说明汉化成功！ 小问题的解决：或许有的人会显示这样的页面： <img src="http://img.blog.csdn.net/20140314231031453?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 那么下载 <a href="http://pan.baidu.com/s/1mg2qKAW" target="_blank" rel="noopener">eclipse.ini</a> 这个文件，把目录下的eclipse.ini文件替换掉。用记事本打开这个文件显示如下内容：</p>
                  <figure class="highlight stylus">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">-startup</span><br><span class="line"> plugins\org<span class="selector-class">.eclipse</span><span class="selector-class">.equinox</span><span class="selector-class">.launcher_1</span>.<span class="number">0.0</span><span class="selector-class">.v20070606</span>.jar</span><br><span class="line"> --launcher.library</span><br><span class="line"> plugins\org<span class="selector-class">.eclipse</span><span class="selector-class">.equinox</span><span class="selector-class">.launcher</span><span class="selector-class">.win32</span><span class="selector-class">.win32</span><span class="selector-class">.x86_1</span>.<span class="number">0.0</span>.v20070523</span><br><span class="line"> -showsplash</span><br><span class="line"> org<span class="selector-class">.eclipse</span>.platform</span><br><span class="line"> --launcher.XXMaxPermSize</span><br><span class="line"> <span class="number">128</span>m</span><br><span class="line"> -vm</span><br><span class="line"> D:\java Jdk <span class="number">1.6</span>\bin\javaw.exe</span><br><span class="line"> -vmargs</span><br><span class="line"> -Xms40m</span><br><span class="line"> -Xmx384m</span><br><span class="line"> -Djava<span class="selector-class">.net</span>.preferIPv4Stack=true</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>-startup是启动所需要的jar文件，这里我把相对路径配好了 -luncher.library我也把相对路径配好了 -xxmaxpermsize是最大内存限制，如果这个数值过大也会出现上述情况，我改成了128m <img src="http://img.blog.csdn.net/20140314231733250?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> -vm 这里是相对的jdk环境设置，这个要设置成你自己的jdk环境，自己写一个路径，在bin目录下，一个javaw.exe文件，如果还不行，那么可能是jdk的版本导致的，我换用了jdk1.6测试成功！如果1.7不能用的话，就换用1.6版本的jdk吧！ 好，小问题暂告一段落，看下图。 <img src="http://img.blog.csdn.net/20140307142719703?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 如果你能新建Dynamic Web Project说明你已经全配置成功啦！欢呼吧骚年们！</p>
                  <h2 id="四、配置tomcat"><a href="#四、配置tomcat" class="headerlink" title="四、配置tomcat"></a><strong>四、配置tomcat</strong></h2>
                  <p><a href="http://pan.baidu.com/s/1eQDYsDG" target="_blank" rel="noopener">下载地址</a> 这个是免安装版，可以直接下载解压，我放在了D盘 <img src="http://img.blog.csdn.net/20140314220235843?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> tomcat环境变量的配置： 1，新建变量名：CATALINA_BASE，变量值：D:\tomcat 6.0\apache-tomcat-6.0.29 2，新建变量名：CATALINA_HOME，变量值：D:\tomcat 6.0\apache-tomcat-6.0.29 【1和2中的路径根据你存放的目录不同而不同】 3，打开PATH，添加变量值：%CATALINA_HOME%\lib;%CATALINA_HOME%\bin 启动tomcat： 在开始菜单输入cmd，然后cd命令定位到tomcat的bin目录，如图 <img src="http://img.blog.csdn.net/20140314220754109?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 然后输入 startup.bat命令，这时tomcat就启动起来了，会弹出一个新的窗口，那个就是tomcat <img src="http://img.blog.csdn.net/20140314220916703?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 下面这个图就是tomcat： <img src="http://img.blog.csdn.net/20140314221457468?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 下面进行测试：在浏览器输入<a href="http://localhost:8080/" target="_blank" rel="noopener">http://localhost:8080/</a> 看看能否出现tomcat界面，如果出现了，那么说明成功了！如果不行，检查环境变量的配置。 <img src="http://img.blog.csdn.net/20140314221834671?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""></p>
                  <h2 id="五、tomcat嵌入eclipse"><a href="#五、tomcat嵌入eclipse" class="headerlink" title="五、tomcat嵌入eclipse"></a><strong>五、tomcat嵌入eclipse</strong></h2>
                  <p>打开eclipse，窗口—&gt;首选项，界面如下： <img src="http://img.blog.csdn.net/20140314222139515?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 点选服务器—&gt;运行时环境—&gt;添加，选择Apach—&gt;tomcat6.0，完成 <img src="http://img.blog.csdn.net/20140314222442921?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 创建之后编辑，添加tomcat的目录，名称自己随便取，jre用缺省jre <img src="http://img.blog.csdn.net/20140314222817437?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 这样在eclipse下方就出现了一个tomcat了，绿色的箭头就是启动，红色的方块是停止 <img src="http://img.blog.csdn.net/20140314223414203?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 可以点击运行tomcat，其中点下方标记的红色处，可以对tomcat进行详细配置，默认配置即可，不用更改了 <img src="http://img.blog.csdn.net/20140314223719093?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""></p>
                  <h2 id="六、测试项目"><a href="#六、测试项目" class="headerlink" title="六、测试项目"></a><strong>六、测试项目</strong></h2>
                  <p>新建一个Dynamic Web Project项目 <img src="http://img.blog.csdn.net/20140314224104578?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 点下一步，我取名为test，服务器选刚才创建的tomcat6.0，然后下一步，下一步，直到完成就好了 <img src="http://img.blog.csdn.net/20140314224443484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 在webcontent目录下面新建一个jsp文件，我的叫a.jsp <img src="http://img.blog.csdn.net/20140314225509390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 我在body区输入了My First Jsp 右击该文件，在服务器上运行，选择tomcat，然后结果如图所示。恭喜你，所有配置都成功啦！ <img src="http://img.blog.csdn.net/20140314230049453?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""> 点选eclipse的窗口,然后web浏览器，选default system web browser，即系统默认浏览器，就可以用自己的浏览器打开界面啦。如图所示 <img src="http://img.blog.csdn.net/20140314230729625?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FjcmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""></p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-11 16:48:44" itemprop="dateCreated datePublished" datetime="2015-03-11T16:48:44+08:00">2015-03-11</time>
                </span>
                <span id="/1809.html" class="post-meta-item leancloud_visitors" data-flag-title="Win7用Eclipse配置JSP开发环境详细教程" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>2.5k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>2 分钟</span>
                </span>
              </div>
            </article>
            <article itemscope itemtype="http://schema.org/Article" class="post-block index" lang="zh-CN">
              <link itemprop="mainEntityOfPage" href="https://cuiqingcai.com/1319.html">
              <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
                <meta itemprop="image" content="/images/avatar.png">
                <meta itemprop="name" content="崔庆才">
                <meta itemprop="description" content="崔庆才的个人站点，记录生活的瞬间，分享学习的心得。">
              </span>
              <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
                <meta itemprop="name" content="静觅">
              </span>
              <header class="post-header">
                <h2 class="post-title" itemprop="name headline">
                  <a class="label"> Python <i class="label-arrow"></i>
                  </a>
                  <a href="/1319.html" class="post-title-link" itemprop="url">Python爬虫利器二之Beautiful Soup的用法</a>
                </h2>
              </header>
              <div class="post-body" itemprop="articleBody">
                <div class="thumb">
                  <img itemprop="contentUrl" class="random">
                </div>
                <div class="excerpt">
                  <p>
                  <p>上一节我们介绍了正则表达式，它的内容其实还是蛮多的，如果一个正则匹配稍有差池，那可能程序就处在永久的循环之中，而且有的小伙伴们也对写正则表达式的写法用得不熟练，没关系，我们还有一个更强大的工具，叫Beautiful Soup，有了它我们可以很方便地提取出HTML或XML标签中的内容，实在是方便，这一节就让我们一起来感受一下Beautiful Soup的强大吧。</p>
                  <h2 id="1-Beautiful-Soup的简介"><a href="#1-Beautiful-Soup的简介" class="headerlink" title="1. Beautiful Soup的简介"></a>1. Beautiful Soup的简介</h2>
                  <p>简单来说，Beautiful Soup是python的一个库，最主要的功能是从网页抓取数据。官方解释如下：</p>
                  <blockquote>
                    <p>Beautiful Soup提供一些简单的、python式的函数用来处理导航、搜索、修改分析树等功能。它是一个工具箱，通过解析文档为用户提供需要抓取的数据，因为简单，所以不需要多少代码就可以写出一个完整的应用程序。 Beautiful Soup自动将输入文档转换为Unicode编码，输出文档转换为utf-8编码。你不需要考虑编码方式，除非文档没有指定一个编码方式，这时，Beautiful Soup就不能自动识别编码方式了。然后，你仅仅需要说明一下原始编码方式就可以了。 Beautiful Soup已成为和lxml、html6lib一样出色的python解释器，为用户灵活地提供不同的解析策略或强劲的速度。</p>
                  </blockquote>
                  <p>废话不多说，我们来试一下吧~</p>
                  <h2 id="2-Beautiful-Soup-安装"><a href="#2-Beautiful-Soup-安装" class="headerlink" title="2. Beautiful Soup 安装"></a>2. Beautiful Soup 安装</h2>
                  <p>Beautiful Soup 3 目前已经停止开发，推荐在现在的项目中使用Beautiful Soup 4，不过它已经被移植到BS4了，也就是说导入时我们需要 import bs4 。所以这里我们用的版本是 Beautiful Soup 4.3.2 (简称BS4)，另外据说 BS4 对 Python3 的支持不够好，不过我用的是 Python2.7.7，如果有小伙伴用的是 Python3 版本，可以考虑下载 BS3 版本。 可以利用 pip 或者 easy_install 来安装，以下两种方法均可</p>
                  <figure class="highlight nginx">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="attribute">easy_install</span> beautifulsoup4</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight cmake">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">pip <span class="keyword">install</span> beautifulsoup4</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果想安装最新的版本，请直接下载安装包来手动安装，也是十分方便的方法。在这里我安装的是 Beautiful Soup 4.3.2 <a href="https://pypi.python.org/pypi/BeautifulSoup/3.2.1" target="_blank" rel="noopener">Beautiful Soup 3.2.1</a><a href="https://pypi.python.org/pypi/beautifulsoup4/4.3.2" target="_blank" rel="noopener">Beautiful Soup 4.3.2</a> 下载完成之后解压 运行下面的命令即可完成安装</p>
                  <figure class="highlight vim">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">sudo <span class="keyword">python</span> setup.<span class="keyword">py</span> install</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>然后需要安装 lxml</p>
                  <figure class="highlight ebnf">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="attribute">easy_install lxml</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight cmake">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">pip <span class="keyword">install</span> lxml</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>另一个可供选择的解析器是纯Python实现的 html5lib , html5lib的解析方式与浏览器相同,可以选择下列方法来安装html5lib:</p>
                  <figure class="highlight nginx">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="attribute">easy_install</span> html5lib</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight cmake">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">pip <span class="keyword">install</span> html5lib</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>Beautiful Soup支持Python标准库中的HTML解析器,还支持一些第三方的解析器，如果我们不安装它，则 Python 会使用 Python默认的解析器，lxml 解析器更加强大，速度更快，推荐安装。</p>
                  <p>&lt;thead”&gt;</p>
                  <p>解析器</p>
                  <p>使用方法</p>
                  <p>优势</p>
                  <p>劣势</p>
                  <p>Python标准库</p>
                  <p>BeautifulSoup(markup, “html.parser”)</p>
                  <ul>
                    <li>Python的内置标准库</li>
                    <li>执行速度适中</li>
                    <li>
                      <p>文档容错能力强</p>
                    </li>
                    <li>
                      <p>Python 2.7.3 or 3.2.2)前 的版本中文档容错能力差</p>
                    </li>
                  </ul>
                  <p>lxml HTML 解析器</p>
                  <p>BeautifulSoup(markup, “lxml”)</p>
                  <ul>
                    <li>速度快</li>
                    <li>
                      <p>文档容错能力强</p>
                    </li>
                    <li>
                      <p>需要安装C语言库</p>
                    </li>
                  </ul>
                  <p>lxml XML 解析器</p>
                  <p>BeautifulSoup(markup, [“lxml”, “xml”])BeautifulSoup(markup, “xml”)</p>
                  <ul>
                    <li>速度快</li>
                    <li>
                      <p>唯一支持XML的解析器</p>
                    </li>
                    <li>
                      <p>需要安装C语言库</p>
                    </li>
                  </ul>
                  <p>html5lib</p>
                  <p>BeautifulSoup(markup, “html5lib”)</p>
                  <ul>
                    <li>最好的容错性</li>
                    <li>以浏览器的方式解析文档</li>
                    <li>
                      <p>生成HTML5格式的文档</p>
                    </li>
                    <li>
                      <p>速度慢</p>
                    </li>
                    <li>不依赖外部扩展</li>
                  </ul>
                  <h2 id="3-开启Beautiful-Soup-之旅"><a href="#3-开启Beautiful-Soup-之旅" class="headerlink" title="3. 开启Beautiful Soup 之旅"></a>3. 开启Beautiful Soup 之旅</h2>
                  <p>在这里先分享官方文档链接，不过内容是有些多，也不够条理，在此本文章做一下整理方便大家参考。 <a href="http://beautifulsoup.readthedocs.org/zh_CN/latest" target="_blank" rel="noopener">官方文档</a></p>
                  <h2 id="4-创建-Beautiful-Soup-对象"><a href="#4-创建-Beautiful-Soup-对象" class="headerlink" title="4. 创建 Beautiful Soup 对象"></a>4. 创建 Beautiful Soup 对象</h2>
                  <p>首先必须要导入 bs4 库</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">from</span> bs4 <span class="keyword">import</span> BeautifulSoup</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>我们创建一个字符串，后面的例子我们便会用它来演示</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">html = """</span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span> <span class="attr">name</span>=<span class="string">"dromouse"</span>&gt;</span><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were three little sisters; and their names were</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>,</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span> and</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>;</span><br><span class="line">and they lived at the bottom of a well.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>...<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">"""</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>创建 beautifulsoup 对象</p>
                  <figure class="highlight ini">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="attr">soup</span> = BeautifulSoup(html)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>另外，我们还可以用本地 HTML 文件来创建对象，例如</p>
                  <figure class="highlight isbl">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="variable">soup</span> = <span class="function"><span class="title">BeautifulSoup</span>(<span class="title">open</span>(<span class="string">'index.html'</span>))</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>上面这句代码便是将本地 index.html 文件打开，用它来创建 soup 对象 下面我们来打印一下 soup 对象的内容，格式化输出</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.prettify()</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span></span><br><span class="line">   The Dormouse's story</span><br><span class="line">  <span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span> <span class="attr">name</span>=<span class="string">"dromouse"</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">b</span>&gt;</span></span><br><span class="line">    The Dormouse's story</span><br><span class="line">   <span class="tag">&lt;/<span class="name">b</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span></span><br><span class="line">   Once upon a time there were three little sisters; and their names were</span><br><span class="line">   <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- Elsie --&gt;</span></span><br><span class="line">   <span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">   ,</span><br><span class="line">   <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span></span><br><span class="line">    Lacie</span><br><span class="line">   <span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">   and</span><br><span class="line">   <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span></span><br><span class="line">    Tillie</span><br><span class="line">   <span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">   ;</span><br><span class="line">and they lived at the bottom of a well.</span><br><span class="line">  <span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span></span><br><span class="line">   ...</span><br><span class="line">  <span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>以上便是输出结果，格式化打印出了它的内容，这个函数经常用到，小伙伴们要记好咯。</p>
                  <h2 id="5-四大对象种类"><a href="#5-四大对象种类" class="headerlink" title="5. 四大对象种类"></a>5. 四大对象种类</h2>
                  <p>Beautiful Soup将复杂HTML文档转换成一个复杂的树形结构,每个节点都是Python对象,所有对象可以归纳为4种:</p>
                  <ul>
                    <li>Tag</li>
                    <li>NavigableString</li>
                    <li>BeautifulSoup</li>
                    <li>Comment</li>
                  </ul>
                  <p>下面我们进行一一介绍</p>
                  <h3 id="（1）Tag"><a href="#（1）Tag" class="headerlink" title="（1）Tag"></a><strong>（1）Tag</strong></h3>
                  <p>Tag 是什么？通俗点讲就是 HTML 中的一个个标签，例如</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">&lt;a <span class="attribute">class</span>=<span class="string">"sister"</span> <span class="attribute">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attribute">id</span>=<span class="string">"link1"</span>&gt;Elsie&lt;/a&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>上面的 title a 等等 HTML 标签加上里面包括的内容就是 Tag，下面我们来感受一下怎样用 Beautiful Soup 来方便地获取 Tags 下面每一段代码中注释部分即为运行结果</p>
                  <figure class="highlight dos">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="built_in">print</span> soup.<span class="built_in">title</span></span><br><span class="line">#&lt;<span class="built_in">title</span>&gt;The Dormouse's story&lt;/<span class="built_in">title</span>&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.head</span><br><span class="line">#<span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.a</span><br><span class="line">#<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.p</span><br><span class="line">#&lt;p <span class="keyword">class</span>="<span class="symbol">title</span>" <span class="symbol">name</span>="<span class="symbol">dromouse</span>"&gt;&lt;<span class="symbol">b</span>&gt;<span class="symbol">The</span> <span class="symbol">Dormouse</span>'<span class="symbol">s</span> <span class="symbol">story</span>&lt;/<span class="symbol">b</span>&gt;&lt;/<span class="symbol">p</span>&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>我们可以利用 soup加标签名轻松地获取这些标签的内容，是不是感觉比正则表达式方便多了？不过有一点是，它查找的是在所有内容中的第一个符合要求的标签，如果要查询所有的标签，我们在后面进行介绍。 我们可以验证一下这些对象的类型</p>
                  <figure class="highlight haskell">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="title">print</span> <span class="class"><span class="keyword">type</span>(<span class="title">soup</span>.<span class="title">a</span>)</span></span><br><span class="line"><span class="meta">#&lt;class 'bs4.element.Tag'&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>对于 Tag，它有两个重要的属性，是 name 和 attrs，下面我们分别来感受一下 <strong>name</strong></p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.name</span><br><span class="line"><span class="builtin-name">print</span> soup.head.name</span><br><span class="line"><span class="comment">#[document]</span></span><br><span class="line"><span class="comment">#head</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>soup 对象本身比较特殊，它的 name 即为 [document]，对于其他内部标签，输出的值便为标签本身的名称。 <strong>attrs</strong></p>
                  <figure class="highlight stylus">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup<span class="selector-class">.p</span>.attrs</span><br><span class="line">#&#123;<span class="string">'class'</span>: [<span class="string">'title'</span>], <span class="string">'name'</span>: <span class="string">'dromouse'</span>&#125;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>在这里，我们把 p 标签的所有属性打印输出了出来，得到的类型是一个字典。 如果我们想要单独获取某个属性，可以这样，例如我们获取它的 class 叫什么</p>
                  <figure class="highlight css">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="selector-tag">print</span> <span class="selector-tag">soup</span><span class="selector-class">.p</span><span class="selector-attr">[<span class="string">'class'</span>]</span></span><br><span class="line">#<span class="selector-attr">[<span class="string">'title'</span>]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>还可以这样，利用get方法，传入属性的名称，二者是等价的</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.p.<span class="builtin-name">get</span>(<span class="string">'class'</span>)</span><br><span class="line"><span class="comment">#['title']</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>我们可以对这些属性和内容等等进行修改，例如</p>
                  <figure class="highlight angelscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.p[<span class="string">'class'</span>]=<span class="string">"newClass"</span></span><br><span class="line">print soup.p</span><br><span class="line">#&lt;p <span class="keyword">class</span>="<span class="symbol">newClass</span>" <span class="symbol">name</span>="<span class="symbol">dromouse</span>"&gt;&lt;<span class="symbol">b</span>&gt;<span class="symbol">The</span> <span class="symbol">Dormouse</span>'<span class="symbol">s</span> <span class="symbol">story</span>&lt;/<span class="symbol">b</span>&gt;&lt;/<span class="symbol">p</span>&gt;</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>还可以对这个属性进行删除，例如</p>
                  <figure class="highlight stylus">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="selector-tag">del</span> soup<span class="selector-class">.p</span>[<span class="string">'class'</span>]</span><br><span class="line">print soup.p</span><br><span class="line">#&lt;<span class="selector-tag">p</span> name=<span class="string">"dromouse"</span>&gt;&lt;b&gt;The Dormouse<span class="string">'s story&lt;/b&gt;&lt;/p&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>不过，对于修改删除的操作，不是我们的主要用途，在此不做详细介绍了，如果有需要，请查看前面提供的官方文档</p>
                  <h3 id="（2）NavigableString"><a href="#（2）NavigableString" class="headerlink" title="（2）NavigableString"></a><strong>（2）NavigableString</strong></h3>
                  <p>既然我们已经得到了标签的内容，那么问题来了，我们要想获取标签内部的文字怎么办呢？很简单，用 .string 即可，例如</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.p.string</span><br><span class="line"><span class="comment">#The Dormouse's story</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>这样我们就轻松获取到了标签里面的内容，想想如果用正则表达式要多麻烦。它的类型是一个 NavigableString，翻译过来叫 可以遍历的字符串，不过我们最好还是称它英文名字吧。 来检查一下它的类型</p>
                  <figure class="highlight moonscript">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="built_in">print</span> <span class="built_in">type</span>(soup.p.<span class="built_in">string</span>)</span><br><span class="line">#&lt;<span class="class"><span class="keyword">class</span> '<span class="title">bs4</span>.<span class="title">element</span>.<span class="title">NavigableString</span>'&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（3）BeautifulSoup"><a href="#（3）BeautifulSoup" class="headerlink" title="（3）BeautifulSoup"></a><strong>（3）BeautifulSoup</strong></h3>
                  <p>BeautifulSoup 对象表示的是一个文档的全部内容.大部分时候,可以把它当作 Tag 对象，是一个特殊的 Tag，我们可以分别获取它的类型，名称，以及属性来感受一下</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> type(soup.name)</span><br><span class="line"><span class="comment">#&lt;type 'unicode'&gt;</span></span><br><span class="line"><span class="builtin-name">print</span> soup.name </span><br><span class="line"><span class="comment"># [document]</span></span><br><span class="line"><span class="builtin-name">print</span> soup.attrs </span><br><span class="line"><span class="comment">#&#123;&#125; 空字典</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（4）Comment"><a href="#（4）Comment" class="headerlink" title="（4）Comment"></a><strong>（4）Comment</strong></h3>
                  <p>Comment 对象是一个特殊类型的 NavigableString 对象，其实输出的内容仍然不包括注释符号，但是如果不好好处理它，可能会对我们的文本处理造成意想不到的麻烦。 我们找一个带注释的标签</p>
                  <figure class="highlight go">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="built_in">print</span> soup.a</span><br><span class="line"><span class="built_in">print</span> soup.a.<span class="keyword">string</span></span><br><span class="line"><span class="built_in">print</span> <span class="keyword">type</span>(soup.a.<span class="keyword">string</span>)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>运行结果如下</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line"> Elsie </span><br><span class="line"><span class="tag">&lt;<span class="name">class</span> '<span class="attr">bs4.element.Comment</span>'&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>a 标签里的内容实际上是注释，但是如果我们利用 .string 来输出它的内容，我们发现它已经把注释符号去掉了，所以这可能会给我们带来不必要的麻烦。 另外我们打印输出下它的类型，发现它是一个 Comment 类型，所以，我们在使用前最好做一下判断，判断代码如下</p>
                  <figure class="highlight livecodeserver">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">if</span> type(soup.<span class="keyword">a</span>.<span class="keyword">string</span>)==bs4.<span class="keyword">element</span>.Comment:</span><br><span class="line">    print soup.<span class="keyword">a</span>.<span class="keyword">string</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>上面的代码中，我们首先判断了它的类型，是否为 Comment 类型，然后再进行其他操作，如打印输出。</p>
                  <h2 id="6-遍历文档树"><a href="#6-遍历文档树" class="headerlink" title="6. 遍历文档树"></a>6. 遍历文档树</h2>
                  <h3 id="（1）直接子节点"><a href="#（1）直接子节点" class="headerlink" title="（1）直接子节点"></a><strong>（1）直接子节点</strong></h3>
                  <blockquote>
                    <p><strong>要点：.contents .children</strong> <strong>属性</strong></p>
                  </blockquote>
                  <p><strong>.contents</strong> tag 的 .content 属性可以将tag的子节点以列表的方式输出</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.head.contents </span><br><span class="line">#<span class="meta">[&lt;title&gt;The Dormouse's story&lt;/title&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>输出方式为列表，我们可以用列表索引来获取它的某一个元素</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.head.contents[0]</span><br><span class="line"><span class="comment">#&lt;title&gt;The Dormouse's story&lt;/title&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>.children</strong> 它返回的不是一个 list，不过我们可以通过遍历获取所有子节点。 我们打印输出 .children 看一下，可以发现它是一个 list 生成器对象</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.head.children</span><br><span class="line"><span class="comment">#&lt;listiterator object at 0x7f71457f5710&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>我们怎样获得里面的内容呢？很简单，遍历一下就好了，代码及结果如下</p>
                  <figure class="highlight css">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="selector-tag">for</span> <span class="selector-tag">child</span> <span class="selector-tag">in</span>  <span class="selector-tag">soup</span><span class="selector-class">.body</span><span class="selector-class">.children</span>:</span><br><span class="line">    <span class="selector-tag">print</span> <span class="selector-tag">child</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span> <span class="attr">name</span>=<span class="string">"dromouse"</span>&gt;</span><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were three little sisters; and their names were</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>,</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span> and</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>;</span><br><span class="line">and they lived at the bottom of a well.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>...<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（2）所有子孙节点"><a href="#（2）所有子孙节点" class="headerlink" title="（2）所有子孙节点"></a><strong>（2）所有子孙节点</strong></h3>
                  <blockquote>
                    <p><strong>知识点：.descendants</strong> <strong>属性</strong></p>
                  </blockquote>
                  <p><strong>.descendants</strong> .contents 和 .children 属性仅包含tag的直接子节点，.descendants 属性可以对所有tag的子孙节点进行递归循环，和 children类似，我们也需要遍历获取其中的内容。</p>
                  <figure class="highlight properties">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="attr">for</span> <span class="string">child in soup.descendants:</span></span><br><span class="line">    <span class="attr">print</span> <span class="string">child</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>运行结果如下，可以发现，所有的节点都被打印出来了，先生最外层的 HTML标签，其次从 head 标签一个个剥离，以此类推。</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span> <span class="attr">name</span>=<span class="string">"dromouse"</span>&gt;</span><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were three little sisters; and their names were</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>,</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span> and</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>;</span><br><span class="line">and they lived at the bottom of a well.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>...<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">The Dormouse's story</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span> <span class="attr">name</span>=<span class="string">"dromouse"</span>&gt;</span><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were three little sisters; and their names were</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>,</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span> and</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>;</span><br><span class="line">and they lived at the bottom of a well.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>...<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span> <span class="attr">name</span>=<span class="string">"dromouse"</span>&gt;</span><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span></span><br><span class="line">The Dormouse's story</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were three little sisters; and their names were</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>,</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span> and</span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>;</span><br><span class="line">and they lived at the bottom of a well.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">Once upon a time there were three little sisters; and their names were</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line"> Elsie </span><br><span class="line">,</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">Lacie</span><br><span class="line"> and</span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span><br><span class="line">Tillie</span><br><span class="line">;</span><br><span class="line">and they lived at the bottom of a well.</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>...<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">...</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（3）节点内容"><a href="#（3）节点内容" class="headerlink" title="（3）节点内容"></a><strong>（3）节点内容</strong></h3>
                  <blockquote>
                    <p>知识点：.string 属性</p>
                  </blockquote>
                  <p>如果tag只有一个 NavigableString 类型子节点,那么这个tag可以使用 .string 得到子节点。如果一个tag仅有一个子节点,那么这个tag也可以使用 .string 方法,输出结果与当前唯一子节点的 .string 结果相同。 通俗点说就是：如果一个标签里面没有标签了，那么 .string 就会返回标签里面的内容。如果标签里面只有唯一的一个标签了，那么 .string 也会返回最里面的内容。例如</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.head.string</span><br><span class="line"><span class="comment">#The Dormouse's story</span></span><br><span class="line"><span class="builtin-name">print</span> soup.title.string</span><br><span class="line"><span class="comment">#The Dormouse's story</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果tag包含了多个子节点,tag就无法确定，string 方法应该调用哪个子节点的内容, .string 的输出结果是 None</p>
                  <figure class="highlight gauss">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">print</span> soup.html.<span class="keyword">string</span></span><br><span class="line"><span class="meta"># None</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（4）多个内容"><a href="#（4）多个内容" class="headerlink" title="（4）多个内容"></a><strong>（4）多个内容</strong></h3>
                  <blockquote>
                    <p><strong>知识点： .strings .stripped_strings 属性</strong></p>
                  </blockquote>
                  <p><strong>.strings</strong> 获取多个内容，不过需要遍历获取，比如下面的例子</p>
                  <figure class="highlight autoit">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">for</span> <span class="built_in">string</span> <span class="keyword">in</span> soup.strings:</span><br><span class="line">    print(repr(<span class="built_in">string</span>))</span><br><span class="line">    <span class="meta"># u<span class="string">"The Dormouse's story"</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'\n\n'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">"The Dormouse's story"</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'\n\n'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Once upon a time there were three little sisters; and their names were\n'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Elsie'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">',\n'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Lacie'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">' and\n'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Tillie'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">';\nand they lived at the bottom of a well.'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'\n\n'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'...'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'\n'</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>.stripped_strings </strong> 输出的字符串中可能包含了很多空格或空行,使用 .stripped_strings 可以去除多余空白内容</p>
                  <figure class="highlight autoit">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">for</span> <span class="built_in">string</span> <span class="keyword">in</span> soup.stripped_strings:</span><br><span class="line">    print(repr(<span class="built_in">string</span>))</span><br><span class="line">    <span class="meta"># u<span class="string">"The Dormouse's story"</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">"The Dormouse's story"</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Once upon a time there were three little sisters; and their names were'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Elsie'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">','</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Lacie'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'and'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'Tillie'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">';\nand they lived at the bottom of a well.'</span></span></span><br><span class="line">    <span class="meta"># u<span class="string">'...'</span></span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（5）父节点"><a href="#（5）父节点" class="headerlink" title="（5）父节点"></a><strong>（5）父节点</strong></h3>
                  <blockquote>
                    <p> <strong>知识点： .parent 属性</strong></p>
                  </blockquote>
                  <figure class="highlight stylus">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="selector-tag">p</span> = soup.p</span><br><span class="line">print <span class="selector-tag">p</span><span class="selector-class">.parent</span>.name</span><br><span class="line">#body</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight maxima">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="built_in">content</span> = soup.head.<span class="built_in">title</span>.<span class="built_in">string</span></span><br><span class="line"><span class="built_in">print</span> <span class="built_in">content</span>.parent.name</span><br><span class="line">#<span class="built_in">title</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（6）全部父节点"><a href="#（6）全部父节点" class="headerlink" title="（6）全部父节点"></a><strong>（6）全部父节点</strong></h3>
                  <blockquote>
                    <p><strong>知识点：.parents 属性</strong></p>
                  </blockquote>
                  <p>通过元素的 .parents 属性可以递归得到元素的所有父辈节点，例如</p>
                  <figure class="highlight maxima">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="built_in">content</span> = soup.head.<span class="built_in">title</span>.<span class="built_in">string</span></span><br><span class="line"><span class="keyword">for</span> parent <span class="keyword">in</span>  <span class="built_in">content</span>.parents:</span><br><span class="line">    <span class="built_in">print</span> parent.name</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xquery">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">title</span><br><span class="line">head</span><br><span class="line">html</span><br><span class="line"><span class="built_in">[document</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（7）兄弟节点"><a href="#（7）兄弟节点" class="headerlink" title="（7）兄弟节点"></a><strong>（7）兄弟节点</strong></h3>
                  <blockquote>
                    <p><strong>知识点：.next_sibling .previous_sibling 属性</strong></p>
                  </blockquote>
                  <p>兄弟节点可以理解为和本节点处在统一级的节点，.next_sibling 属性获取了该节点的下一个兄弟节点，.previous_sibling 则与之相反，如果节点不存在，则返回 None 注意：实际文档中的tag的 .next_sibling 和 .previous_sibling 属性通常是字符串或空白，因为空白或者换行也可以被视作一个节点，所以得到的结果可能是空白或者换行</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.p.next_sibling</span><br><span class="line">#       实际该处为空白</span><br><span class="line">print soup.p.prev_sibling</span><br><span class="line">#None   没有前一个兄弟节点，返回 None</span><br><span class="line">print soup.p.next_sibling.next_sibling</span><br><span class="line">#<span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were three little sisters; and their names were</span><br><span class="line">#<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>,</span><br><span class="line">#<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span> and</span><br><span class="line">#<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>;</span><br><span class="line">#and they lived at the bottom of a well.<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">#下一个节点的下一个兄弟节点是我们可以看到的节点</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（8）全部兄弟节点"><a href="#（8）全部兄弟节点" class="headerlink" title="（8）全部兄弟节点"></a><strong>（8）全部兄弟节点</strong></h3>
                  <blockquote>
                    <p><strong>知识点：.next_siblings .previous_siblings 属性</strong></p>
                  </blockquote>
                  <p>通过 .next_siblings 和 .previous_siblings 属性可以对当前节点的兄弟节点迭代输出</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">for</span> sibling <span class="keyword">in</span> soup.a.next_siblings:</span><br><span class="line">    <span class="builtin-name">print</span>(repr(sibling))</span><br><span class="line">    # u<span class="string">',\n'</span></span><br><span class="line">    # &lt;a <span class="attribute">class</span>=<span class="string">"sister"</span> <span class="attribute">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attribute">id</span>=<span class="string">"link2"</span>&gt;Lacie&lt;/a&gt;</span><br><span class="line">    # u<span class="string">' and\n'</span></span><br><span class="line">    # &lt;a <span class="attribute">class</span>=<span class="string">"sister"</span> <span class="attribute">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attribute">id</span>=<span class="string">"link3"</span>&gt;Tillie&lt;/a&gt;</span><br><span class="line">    # u<span class="string">'; and they lived at the bottom of a well.'</span></span><br><span class="line">    # None</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（9）前后节点"><a href="#（9）前后节点" class="headerlink" title="（9）前后节点"></a><strong>（9）前后节点</strong></h3>
                  <blockquote>
                    <p><strong>知识点：.next_element .previous_element 属性</strong></p>
                  </blockquote>
                  <p>与 .next_sibling .previous_sibling 不同，它并不是针对于兄弟节点，而是在所有节点，不分层次 比如 head 节点为</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span><span class="tag">&lt;<span class="name">title</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">title</span>&gt;</span><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>那么它的下一个节点便是 title，它是不分层次关系的</p>
                  <figure class="highlight routeros">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="builtin-name">print</span> soup.head.next_element</span><br><span class="line"><span class="comment">#&lt;title&gt;The Dormouse's story&lt;/title&gt;</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（10）所有前后节点"><a href="#（10）所有前后节点" class="headerlink" title="（10）所有前后节点"></a><strong>（10）所有前后节点</strong></h3>
                  <blockquote>
                    <p><strong>知识点：.next_elements .previous_elements 属性</strong></p>
                  </blockquote>
                  <p>通过 .next_elements 和 .previous_elements 的迭代器就可以向前或向后访问文档的解析内容,就好像文档正在被解析一样</p>
                  <figure class="highlight clean">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">for element <span class="keyword">in</span> last_a_tag.next_elements:</span><br><span class="line">    print(repr(element))</span><br><span class="line"># u<span class="string">'Tillie'</span></span><br><span class="line"># u<span class="string">';\nand they lived at the bottom of a well.'</span></span><br><span class="line"># u<span class="string">'\n\n'</span></span><br><span class="line"># &lt;p <span class="keyword">class</span>=<span class="string">"story"</span>&gt;...&lt;/p&gt;</span><br><span class="line"># u<span class="string">'...'</span></span><br><span class="line"># u<span class="string">'\n'</span></span><br><span class="line"># None</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>以上是遍历文档树的基本用法。</p>
                  <h2 id="7-搜索文档树"><a href="#7-搜索文档树" class="headerlink" title="7.搜索文档树"></a>7.搜索文档树</h2>
                  <h3 id="（1）find-all-name-attrs-recursive-text-kwargs"><a href="#（1）find-all-name-attrs-recursive-text-kwargs" class="headerlink" title="（1）find_all( name , attrs , recursive , text , **kwargs )"></a>（1）find_all( name , attrs , recursive , text , **kwargs )</h3>
                  <p>find_all() 方法搜索当前tag的所有tag子节点,并判断是否符合过滤器的条件 <strong>1）name 参数</strong> name 参数可以查找所有名字为 name 的tag,字符串对象会被自动忽略掉 <strong>A.传字符串</strong> 最简单的过滤器是字符串.在搜索方法中传入一个字符串参数,Beautiful Soup会查找与字符串完整匹配的内容,下面的例子用于查找文档中所有的<b>标签</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(<span class="symbol">'b</span>')</span><br><span class="line"># <span class="meta">[&lt;b&gt;The Dormouse's story&lt;/b&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.find_all('a')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>B.传正则表达式</strong> 如果传入正则表达式作为参数,Beautiful Soup会通过正则表达式的 match() 来匹配内容.下面例子中找出所有以b开头的标签,这表示

                    <body>和<b>标签都应该被找到
                  </p>
                  <figure class="highlight crmsh">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">import re</span><br><span class="line">for <span class="keyword">tag</span> <span class="title">in</span> soup.find_all(re.compile(<span class="string">"^b"</span>)):</span><br><span class="line">    print(<span class="keyword">tag</span>.name)</span><br><span class="line"><span class="comment"># body</span></span><br><span class="line"><span class="comment"># b</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>C.传列表</strong> 如果传入列表参数,Beautiful Soup会将与列表中任一元素匹配的内容返回.下面代码找到文档中所有<a>标签和<b>标签</p>
                  <figure class="highlight scala">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all([<span class="string">"a"</span>, <span class="string">"b"</span>])</span><br><span class="line"># [&lt;b&gt;<span class="type">The</span> <span class="type">Dormouse</span><span class="symbol">'s</span> story&lt;/b&gt;,</span><br><span class="line">#  &lt;a <span class="class"><span class="keyword">class</span></span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/elsie"</span> id=<span class="string">"link1"</span>&gt;<span class="type">Elsie</span>&lt;/a&gt;,</span><br><span class="line">#  &lt;a <span class="class"><span class="keyword">class</span></span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/lacie"</span> id=<span class="string">"link2"</span>&gt;<span class="type">Lacie</span>&lt;/a&gt;,</span><br><span class="line">#  &lt;a <span class="class"><span class="keyword">class</span></span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/tillie"</span> id=<span class="string">"link3"</span>&gt;<span class="type">Tillie</span>&lt;/a&gt;]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>D.传 True</strong> True 可以匹配任何值,下面代码查找到所有的tag,但是不会返回字符串节点</p>
                  <figure class="highlight vala">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="keyword">for</span> tag in soup.find_all(True):</span><br><span class="line">    print(tag.name)</span><br><span class="line"><span class="meta"># html</span></span><br><span class="line"><span class="meta"># head</span></span><br><span class="line"><span class="meta"># title</span></span><br><span class="line"><span class="meta"># body</span></span><br><span class="line"><span class="meta"># p</span></span><br><span class="line"><span class="meta"># b</span></span><br><span class="line"><span class="meta"># p</span></span><br><span class="line"><span class="meta"># a</span></span><br><span class="line"><span class="meta"># a</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>E.传方法</strong> 如果没有合适过滤器,那么还可以定义一个方法,方法只接受一个元素参数 <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html#id85" target="_blank" rel="noopener">[4]</a> ,如果这个方法返回 True 表示当前元素匹配并且被找到,如果不是则反回 False 下面方法校验了当前元素,如果包含 class 属性却不包含 id 属性,那么将返回 True:</p>
                  <figure class="highlight ruby">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">has_class_but_no_id</span><span class="params">(tag)</span></span><span class="symbol">:</span></span><br><span class="line">    <span class="keyword">return</span> tag.has_attr(<span class="string">'class'</span>) <span class="keyword">and</span> <span class="keyword">not</span> tag.has_attr(<span class="string">'id'</span>)</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>将这个方法作为参数传入 find_all() 方法,将得到所有
                  <p>标签:</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(has_class_but_no_id)</span><br><span class="line"># [<span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"title"</span>&gt;</span><span class="tag">&lt;<span class="name">b</span>&gt;</span>The Dormouse's story<span class="tag">&lt;/<span class="name">b</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span>,</span><br><span class="line">#  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>Once upon a time there were...<span class="tag">&lt;/<span class="name">p</span>&gt;</span>,</span><br><span class="line">#  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"story"</span>&gt;</span>...<span class="tag">&lt;/<span class="name">p</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>2）keyword 参数</strong></p>
                  <blockquote>
                    <p><strong>注意：如果一个指定名字的参数不是搜索内置的参数名,搜索时会把该参数当作指定名字tag的属性来搜索,如果包含一个名字为 id 的参数,Beautiful Soup会搜索每个tag的”id”属性</strong></p>
                  </blockquote>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(id='link2')</span><br><span class="line"># <span class="meta">[&lt;a class="sister" href="http://example.com/lacie" id="link2"&gt;Lacie&lt;/a&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>如果传入 href 参数,Beautiful Soup会搜索每个tag的”href”属性</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(href=re.compile(<span class="string">"elsie"</span>))</span><br><span class="line"># <span class="meta">[&lt;a class="sister" href="http://example.com/elsie" id="link1"&gt;Elsie&lt;/a&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>使用多个指定名字的参数可以同时过滤tag的多个属性</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(href=re.compile(<span class="string">"elsie"</span>), id='link1')</span><br><span class="line"># <span class="meta">[&lt;a class="sister" href="http://example.com/elsie" id="link1"&gt;three&lt;/a&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>在这里我们想用 class 过滤，不过 class 是 python 的关键词，这怎么办？加个下划线就可以</p>
                  <figure class="highlight clean">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(<span class="string">"a"</span>, class_=<span class="string">"sister"</span>)</span><br><span class="line"># [&lt;a <span class="keyword">class</span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/elsie"</span> id=<span class="string">"link1"</span>&gt;Elsie&lt;/a&gt;,</span><br><span class="line">#  &lt;a <span class="keyword">class</span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/lacie"</span> id=<span class="string">"link2"</span>&gt;Lacie&lt;/a&gt;,</span><br><span class="line">#  &lt;a <span class="keyword">class</span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/tillie"</span> id=<span class="string">"link3"</span>&gt;Tillie&lt;/a&gt;]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>有些tag属性在搜索不能使用,比如HTML5中的 data-* 属性</p>
                  <figure class="highlight reasonml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">data_soup = <span class="constructor">BeautifulSoup('&lt;<span class="params">div</span> <span class="params">data</span>-<span class="params">foo</span>=<span class="string">"value"</span>&gt;<span class="params">foo</span>!&lt;<span class="operator">/</span><span class="params">div</span>&gt;')</span></span><br><span class="line">data_soup.find<span class="constructor">_all(<span class="params">data</span>-<span class="params">foo</span>=<span class="string">"value"</span>)</span></span><br><span class="line"># SyntaxError: keyword can't be an expression</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>但是可以通过 find_all() 方法的 attrs 参数定义一个字典参数来搜索包含特殊属性的tag</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">data_soup.find_all(attrs=&#123;<span class="string">"data-foo"</span>: <span class="string">"value"</span>&#125;)</span><br><span class="line"># <span class="meta">[&lt;div data-foo="value"&gt;foo!&lt;/div&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>3）text 参数</strong> 通过 text 参数可以搜搜文档中的字符串内容.与 name 参数的可选值一样, text 参数接受 字符串 , 正则表达式 , 列表, True</p>
                  <figure class="highlight awk">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(text=<span class="string">"Elsie"</span>)</span><br><span class="line"><span class="comment"># [u'Elsie']</span></span><br><span class="line"></span><br><span class="line">soup.find_all(text=[<span class="string">"Tillie"</span>, <span class="string">"Elsie"</span>, <span class="string">"Lacie"</span>])</span><br><span class="line"><span class="comment"># [u'Elsie', u'Lacie', u'Tillie']</span></span><br><span class="line"></span><br><span class="line">soup.find_all(text=re.compile(<span class="string">"Dormouse"</span>))</span><br><span class="line">[<span class="string">u"The Dormouse's story"</span>, <span class="string">u"The Dormouse's story"</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>4）limit 参数</strong> find_all() 方法返回全部的搜索结构,如果文档树很大那么搜索会很慢.如果我们不需要全部结果,可以使用 limit 参数限制返回结果的数量.效果与SQL中的limit关键字类似,当搜索到的结果数量达到 limit 的限制时,就停止搜索返回结果. 文档树中有3个tag符合搜索条件,但结果只返回了2个,因为我们限制了返回数量</p>
                  <figure class="highlight clean">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.find_all(<span class="string">"a"</span>, limit=<span class="number">2</span>)</span><br><span class="line"># [&lt;a <span class="keyword">class</span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/elsie"</span> id=<span class="string">"link1"</span>&gt;Elsie&lt;/a&gt;,</span><br><span class="line">#  &lt;a <span class="keyword">class</span>=<span class="string">"sister"</span> href=<span class="string">"http://example.com/lacie"</span> id=<span class="string">"link2"</span>&gt;Lacie&lt;/a&gt;]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p><strong>5）recursive 参数</strong> 调用tag的 find_all() 方法时,Beautiful Soup会检索当前tag的所有子孙节点,如果只想搜索tag的直接子节点,可以使用参数 recursive=False . 一段简单的文档:</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span></span><br><span class="line">   The Dormouse's story</span><br><span class="line">  <span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">...</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>是否使用 recursive 参数的搜索结果:</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup.html.find_all(<span class="string">"title"</span>)</span><br><span class="line"># <span class="meta">[&lt;title&gt;The Dormouse's story&lt;/title&gt;]</span></span><br><span class="line"></span><br><span class="line">soup.html.find_all(<span class="string">"title"</span>, recursive=False)</span><br><span class="line"># []</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（2）find-name-attrs-recursive-text-kwargs"><a href="#（2）find-name-attrs-recursive-text-kwargs" class="headerlink" title="（2）find( name , attrs , recursive , text , **kwargs )"></a>（2）find( name , attrs , recursive , text , **kwargs )</h3>
                  <p>它与 find_all() 方法唯一的区别是 find_all() 方法的返回结果是值包含一个元素的列表,而 find() 方法直接返回结果</p>
                  <h3 id="（3）find-parents-find-parent"><a href="#（3）find-parents-find-parent" class="headerlink" title="（3）find_parents()  find_parent()"></a>（3）find_parents() find_parent()</h3>
                  <p>find_all() 和 find() 只搜索当前节点的所有子节点,孙子节点等. find_parents() 和 find_parent() 用来搜索当前节点的父辈节点,搜索方法与普通tag的搜索方法相同,搜索文档搜索文档包含的内容</p>
                  <h3 id="（4）find-next-siblings-find-next-sibling"><a href="#（4）find-next-siblings-find-next-sibling" class="headerlink" title="（4）find_next_siblings()  find_next_sibling()"></a>（4）find_next_siblings() find_next_sibling()</h3>
                  <p>这2个方法通过 .next_siblings 属性对当 tag 的所有后面解析的兄弟 tag 节点进行迭代, find_next_siblings() 方法返回所有符合条件的后面的兄弟节点,find_next_sibling() 只返回符合条件的后面的第一个tag节点</p>
                  <h3 id="（5）find-previous-siblings-find-previous-sibling"><a href="#（5）find-previous-siblings-find-previous-sibling" class="headerlink" title="（5）find_previous_siblings()  find_previous_sibling()"></a>（5）find_previous_siblings() find_previous_sibling()</h3>
                  <p>这2个方法通过 .previous_siblings 属性对当前 tag 的前面解析的兄弟 tag 节点进行迭代, find_previous_siblings() 方法返回所有符合条件的前面的兄弟节点, find_previous_sibling() 方法返回第一个符合条件的前面的兄弟节点</p>
                  <h3 id="（6）find-all-next-find-next"><a href="#（6）find-all-next-find-next" class="headerlink" title="（6）find_all_next()  find_next()"></a>（6）find_all_next() find_next()</h3>
                  <p>这2个方法通过 .next_elements 属性对当前 tag 的之后的 tag 和字符串进行迭代, find_all_next() 方法返回所有符合条件的节点, find_next() 方法返回第一个符合条件的节点</p>
                  <h3 id="（7）find-all-previous-和-find-previous"><a href="#（7）find-all-previous-和-find-previous" class="headerlink" title="（7）find_all_previous() 和 find_previous()"></a>（7）find_all_previous() 和 find_previous()</h3>
                  <p>这2个方法通过 .previous_elements 属性对当前节点前面的 tag 和字符串进行迭代, find_all_previous() 方法返回所有符合条件的节点, find_previous()方法返回第一个符合条件的节点</p>
                  <blockquote>
                    <p><strong>注：以上（2）（3）（4）（5）（6）（7）方法参数用法与 find_all() 完全相同，原理均类似，在此不再赘述。</strong></p>
                  </blockquote>
                  <h2 id="8-CSS选择器"><a href="#8-CSS选择器" class="headerlink" title="8.CSS选择器"></a>8.CSS选择器</h2>
                  <p>我们在写 CSS 时，标签名不加任何修饰，类名前加点，id名前加 #，在这里我们也可以利用类似的方法来筛选元素，用到的方法是 <strong>soup.select()，</strong>返回类型是 <strong>list</strong></p>
                  <h3 id="（1）通过标签名查找"><a href="#（1）通过标签名查找" class="headerlink" title="（1）通过标签名查找"></a>（1）通过标签名查找</h3>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('title') </span><br><span class="line">#<span class="meta">[&lt;title&gt;The Dormouse's story&lt;/title&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('a')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select(<span class="symbol">'b</span>')</span><br><span class="line">#<span class="meta">[&lt;b&gt;The Dormouse's story&lt;/b&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（2）通过类名查找"><a href="#（2）通过类名查找" class="headerlink" title="（2）通过类名查找"></a>（2）通过类名查找</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('.sister')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（3）通过-id-名查找"><a href="#（3）通过-id-名查找" class="headerlink" title="（3）通过 id 名查找"></a>（3）通过 id 名查找</h3>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('#link1')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（4）组合查找"><a href="#（4）组合查找" class="headerlink" title="（4）组合查找"></a>（4）组合查找</h3>
                  <p>组合查找即和写 class 文件时，标签名与类名、id名进行的组合原理是一样的，例如查找 p 标签中，id 等于 link1的内容，二者需要用空格分开</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('p #link1')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>直接子标签查找</p>
                  <figure class="highlight fsharp">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select(<span class="string">"head &gt; title"</span>)</span><br><span class="line">#<span class="meta">[&lt;title&gt;The Dormouse's story&lt;/title&gt;]</span></span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <h3 id="（5）属性查找"><a href="#（5）属性查找" class="headerlink" title="（5）属性查找"></a>（5）属性查找</h3>
                  <p>查找时还可以加入属性元素，属性需要用中括号括起来，注意属性和标签属于同一节点，所以中间不能加空格，否则会无法匹配到。</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('a[class="sister"]')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/lacie"</span> <span class="attr">id</span>=<span class="string">"link2"</span>&gt;</span>Lacie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>, <span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/tillie"</span> <span class="attr">id</span>=<span class="string">"link3"</span>&gt;</span>Tillie<span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('a[href="http://example.com/elsie"]')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>同样，属性仍然可以与上述查找方式组合，不在同一节点的空格隔开，同一节点的不加空格</p>
                  <figure class="highlight xml">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">print soup.select('p a[href="http://example.com/elsie"]')</span><br><span class="line">#[<span class="tag">&lt;<span class="name">a</span> <span class="attr">class</span>=<span class="string">"sister"</span> <span class="attr">href</span>=<span class="string">"http://example.com/elsie"</span> <span class="attr">id</span>=<span class="string">"link1"</span>&gt;</span><span class="comment">&lt;!-- Elsie --&gt;</span><span class="tag">&lt;/<span class="name">a</span>&gt;</span>]</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>以上的 select 方法返回的结果都是列表形式，可以遍历形式输出，然后用 get_text() 方法来获取它的内容。</p>
                  <figure class="highlight go">
                    <table>
                      <tr>
                        <td class="gutter">
                          <pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre>
                        </td>
                        <td class="code">
                          <pre><span class="line">soup = BeautifulSoup(html, <span class="string">'lxml'</span>)</span><br><span class="line"><span class="built_in">print</span> <span class="keyword">type</span>(soup.<span class="keyword">select</span>(<span class="string">'title'</span>))</span><br><span class="line"><span class="built_in">print</span> soup.<span class="keyword">select</span>(<span class="string">'title'</span>)[<span class="number">0</span>].get_text()</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> title in soup.<span class="keyword">select</span>(<span class="string">'title'</span>):</span><br><span class="line">    <span class="built_in">print</span> title.get_text()</span><br></pre>
                        </td>
                      </tr>
                    </table>
                  </figure>
                  <p>好，这就是另一种与 find_all 方法有异曲同工之妙的查找方法，是不是感觉很方便？</p>
                  <h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2>
                  <p>本篇内容比较多，把 Beautiful Soup 的方法进行了大部分整理和总结，不过这还不算完全，仍然有 Beautiful Soup 的修改删除功能，不过这些功能用得比较少，只整理了查找提取的方法，希望对大家有帮助！小伙伴们加油！ 熟练掌握了 Beautiful Soup，一定会给你带来太多方便，加油吧！</p>
                  </p>
                </div>
              </div>
              <div class="post-meta">
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-user"></i>
                  </span>
                  <span class="post-meta-item-text">作者</span>
                  <span><a href="/authors/崔庆才" class="author" itemprop="url" rel="index">崔庆才</a></span>
                </span>
                <span class="post-meta-item">
                  <span class="post-meta-item-icon">
                    <i class="far fa-calendar"></i>
                  </span>
                  <span class="post-meta-item-text">发表于</span>
                  <time title="创建时间：2015-03-11 00:18:55" itemprop="dateCreated datePublished" datetime="2015-03-11T00:18:55+08:00">2015-03-11</time>
                </span>
                <span id="/1319.html" class="post-meta-item leancloud_visitors" data-flag-title="Python爬虫利器二之Beautiful Soup的用法" title="阅读次数">
                  <span class="post-meta-item-icon">
                    <i class="fa fa-eye"></i>
                  </span>
                  <span class="post-meta-item-text">阅读次数：</span>
                  <span class="leancloud-visitors-count"></span>
                </span>
                <span class="post-meta-item" title="本文字数">
                  <span class="post-meta-item-icon">
                    <i class="far fa-file-word"></i>
                  </span>
                  <span class="post-meta-item-text">本文字数：</span>
                  <span>20k</span>
                </span>
                <span class="post-meta-item" title="阅读时长">
                  <span class="post-meta-item-icon">
                    <i class="far fa-clock"></i>
                  </span>
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                  <span>18 分钟</span>
                </span>
              </div>
            </article>
            <script>
              document.querySelectorAll('.random').forEach(item => item.src = "https://picsum.photos/id/" + Math.floor(Math.random() * Math.floor(300)) + "/200/133")

            </script>
            <nav class="pagination">
              <a class="extend prev" rel="prev" href="/page/26/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/26/">26</a><span class="page-number current">27</span><a class="page-number" href="/page/28/">28</a><span class="space">&hellip;</span><a class="page-number" href="/page/31/">31</a><a class="extend next" rel="next" href="/page/28/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
            </nav>
          </div>
          <script>
            window.addEventListener('tabs:register', () =>
            {
              let
              {
                activeClass
              } = CONFIG.comments;
              if (CONFIG.comments.storage)
              {
                activeClass = localStorage.getItem('comments_active') || activeClass;
              }
              if (activeClass)
              {
                let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
                if (activeTab)
                {
                  activeTab.click();
                }
              }
            });
            if (CONFIG.comments.storage)
            {
              window.addEventListener('tabs:click', event =>
              {
                if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
                let commentClass = event.target.classList[1];
                localStorage.setItem('comments_active', commentClass);
              });
            }

          </script>
        </div>
        <div class="toggle sidebar-toggle">
          <span class="toggle-line toggle-line-first"></span>
          <span class="toggle-line toggle-line-middle"></span>
          <span class="toggle-line toggle-line-last"></span>
        </div>
        <aside class="sidebar">
          <div class="sidebar-inner">
            <ul class="sidebar-nav motion-element">
              <li class="sidebar-nav-toc"> 文章目录 </li>
              <li class="sidebar-nav-overview"> 站点概览 </li>
            </ul>
            <!--noindex-->
            <div class="post-toc-wrap sidebar-panel">
            </div>
            <!--/noindex-->
            <div class="site-overview-wrap sidebar-panel">
              <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
                <img class="site-author-image" itemprop="image" alt="崔庆才" src="/images/avatar.png">
                <p class="site-author-name" itemprop="name">崔庆才</p>
                <div class="site-description" itemprop="description">崔庆才的个人站点，记录生活的瞬间，分享学习的心得。</div>
              </div>
              <div class="site-state-wrap motion-element">
                <nav class="site-state">
                  <div class="site-state-item site-state-posts">
                    <a href="/archives/">
                      <span class="site-state-item-count">608</span>
                      <span class="site-state-item-name">日志</span>
                    </a>
                  </div>
                  <div class="site-state-item site-state-categories">
                    <a href="/categories/">
                      <span class="site-state-item-count">24</span>
                      <span class="site-state-item-name">分类</span></a>
                  </div>
                  <div class="site-state-item site-state-tags">
                    <a href="/tags/">
                      <span class="site-state-item-count">156</span>
                      <span class="site-state-item-name">标签</span></a>
                  </div>
                </nav>
              </div>
              <div class="links-of-author motion-element">
                <span class="links-of-author-item">
                  <a href="https://github.com/Germey" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Germey" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
                </span>
                <span class="links-of-author-item">
                  <a href="mailto:cqc@cuiqingcai.com.com" title="邮件 → mailto:cqc@cuiqingcai.com.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>邮件</a>
                </span>
                <span class="links-of-author-item">
                  <a href="https://weibo.com/cuiqingcai" title="微博 → https:&#x2F;&#x2F;weibo.com&#x2F;cuiqingcai" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>微博</a>
                </span>
                <span class="links-of-author-item">
                  <a href="https://www.zhihu.com/people/Germey" title="知乎 → https:&#x2F;&#x2F;www.zhihu.com&#x2F;people&#x2F;Germey" rel="noopener" target="_blank"><i class="fa fa-magic fa-fw"></i>知乎</a>
                </span>
              </div>
            </div>
            <div style=" width: 100%;" class="sidebar-panel sidebar-panel-image sidebar-panel-active">
              <a href="https://tutorial.lengyue.video/?coupon=12ef4b1a-a3db-11ea-bb37-0242ac130002_cqx_850" target="_blank" rel="noopener">
                <img src="https://qiniu.cuiqingcai.com/bco2a.png" style=" width: 100%;">
              </a>
            </div>
            <div style=" width: 100%;" class="sidebar-panel sidebar-panel-image sidebar-panel-active">
              <a href="http://www.ipidea.net/?utm-source=cqc&utm-keyword=?cqc" target="_blank" rel="noopener">
                <img src="https://qiniu.cuiqingcai.com/0ywun.png" style=" width: 100%;">
              </a>
            </div>
            <div class="sidebar-panel sidebar-panel-tags sidebar-panel-active">
              <h4 class="name"> 标签云 </h4>
              <div class="content">
                <a href="/tags/2048/" style="font-size: 10px;">2048</a> <a href="/tags/API/" style="font-size: 10px;">API</a> <a href="/tags/Bootstrap/" style="font-size: 11.25px;">Bootstrap</a> <a href="/tags/CDN/" style="font-size: 10px;">CDN</a> <a href="/tags/CQC/" style="font-size: 10px;">CQC</a> <a href="/tags/CSS/" style="font-size: 10px;">CSS</a> <a href="/tags/CSS-%E5%8F%8D%E7%88%AC%E8%99%AB/" style="font-size: 10px;">CSS 反爬虫</a> <a href="/tags/CV/" style="font-size: 10px;">CV</a> <a href="/tags/Django/" style="font-size: 10px;">Django</a> <a href="/tags/Eclipse/" style="font-size: 11.25px;">Eclipse</a> <a href="/tags/FTP/" style="font-size: 10px;">FTP</a> <a href="/tags/Git/" style="font-size: 10px;">Git</a> <a href="/tags/GitHub/" style="font-size: 13.75px;">GitHub</a> <a href="/tags/HTML5/" style="font-size: 10px;">HTML5</a> <a href="/tags/Hexo/" style="font-size: 10px;">Hexo</a> <a href="/tags/IT/" style="font-size: 10px;">IT</a> <a href="/tags/JSP/" style="font-size: 10px;">JSP</a> <a href="/tags/JavaScript/" style="font-size: 10px;">JavaScript</a> <a href="/tags/K8s/" style="font-size: 10px;">K8s</a> <a href="/tags/LOGO/" style="font-size: 10px;">LOGO</a> <a href="/tags/Linux/" style="font-size: 10px;">Linux</a> <a href="/tags/MIUI/" style="font-size: 10px;">MIUI</a> <a href="/tags/MongoDB/" style="font-size: 10px;">MongoDB</a> <a href="/tags/Mysql/" style="font-size: 10px;">Mysql</a> <a href="/tags/NBA/" style="font-size: 10px;">NBA</a> <a href="/tags/PHP/" style="font-size: 11.25px;">PHP</a> <a href="/tags/PS/" style="font-size: 10px;">PS</a> <a href="/tags/Pathlib/" style="font-size: 10px;">Pathlib</a> <a href="/tags/PhantomJS/" style="font-size: 10px;">PhantomJS</a> <a href="/tags/Python/" style="font-size: 15px;">Python</a> <a href="/tags/Python3/" style="font-size: 12.5px;">Python3</a> <a href="/tags/Pythonic/" style="font-size: 10px;">Pythonic</a> <a href="/tags/QQ/" style="font-size: 10px;">QQ</a> <a href="/tags/Redis/" style="font-size: 10px;">Redis</a> <a href="/tags/SAE/" style="font-size: 10px;">SAE</a> <a href="/tags/SSH/" style="font-size: 10px;">SSH</a> <a href="/tags/SVG/" style="font-size: 10px;">SVG</a> <a href="/tags/Scrapy/" style="font-size: 10px;">Scrapy</a> <a href="/tags/Scrapy-redis/" style="font-size: 10px;">Scrapy-redis</a> <a href="/tags/Scrapy%E5%88%86%E5%B8%83%E5%BC%8F/" style="font-size: 10px;">Scrapy分布式</a> <a href="/tags/Selenium/" style="font-size: 10px;">Selenium</a> <a href="/tags/TKE/" style="font-size: 10px;">TKE</a> <a href="/tags/Ubuntu/" style="font-size: 11.25px;">Ubuntu</a> <a href="/tags/VS-Code/" style="font-size: 10px;">VS Code</a> <a href="/tags/Vs-Code/" style="font-size: 10px;">Vs Code</a> <a href="/tags/Vue/" style="font-size: 11.25px;">Vue</a> <a href="/tags/Webpack/" style="font-size: 10px;">Webpack</a> <a href="/tags/Windows/" style="font-size: 10px;">Windows</a> <a href="/tags/Winpcap/" style="font-size: 10px;">Winpcap</a> <a href="/tags/WordPress/" style="font-size: 13.75px;">WordPress</a> <a href="/tags/Youtube/" style="font-size: 11.25px;">Youtube</a> <a href="/tags/android/" style="font-size: 10px;">android</a> <a href="/tags/ansible/" style="font-size: 10px;">ansible</a> <a href="/tags/cocos2d-x/" style="font-size: 10px;">cocos2d-x</a> <a href="/tags/e6/" style="font-size: 10px;">e6</a> <a href="/tags/fitvids/" style="font-size: 10px;">fitvids</a> <a href="/tags/git/" style="font-size: 11.25px;">git</a> <a href="/tags/json/" style="font-size: 10px;">json</a> <a href="/tags/js%E9%80%86%E5%90%91/" style="font-size: 10px;">js逆向</a> <a href="/tags/kubernetes/" style="font-size: 10px;">kubernetes</a> <a href="/tags/log/" style="font-size: 10px;">log</a> <a href="/tags/logging/" style="font-size: 10px;">logging</a> <a href="/tags/matlab/" style="font-size: 11.25px;">matlab</a> <a href="/tags/python/" style="font-size: 20px;">python</a> <a href="/tags/pytube/" style="font-size: 11.25px;">pytube</a> <a href="/tags/pywin32/" style="font-size: 10px;">pywin32</a> <a href="/tags/style/" style="font-size: 10px;">style</a> <a href="/tags/tomcat/" style="font-size: 10px;">tomcat</a> <a href="/tags/ubuntu/" style="font-size: 10px;">ubuntu</a> <a href="/tags/uwsgi/" style="font-size: 10px;">uwsgi</a> <a href="/tags/vsftpd/" style="font-size: 10px;">vsftpd</a> <a href="/tags/wamp/" style="font-size: 10px;">wamp</a> <a href="/tags/wineQQ/" style="font-size: 10px;">wineQQ</a> <a href="/tags/%E4%B8%83%E7%89%9B/" style="font-size: 11.25px;">七牛</a> <a href="/tags/%E4%B8%8A%E6%B5%B7/" style="font-size: 10px;">上海</a> <a href="/tags/%E4%B8%AA%E4%BA%BA%E7%BD%91%E7%AB%99/" style="font-size: 10px;">个人网站</a> <a href="/tags/%E4%B8%BB%E9%A2%98/" style="font-size: 10px;">主题</a> <a href="/tags/%E4%BA%91%E4%BA%A7%E5%93%81/" style="font-size: 10px;">云产品</a> <a href="/tags/%E4%BA%91%E5%AD%98%E5%82%A8/" style="font-size: 10px;">云存储</a> <a href="/tags/%E4%BA%AC%E4%B8%9C%E4%BA%91/" style="font-size: 10px;">京东云</a> <a href="/tags/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD/" style="font-size: 12.5px;">人工智能</a> <a href="/tags/%E4%BB%A3%E7%90%86/" style="font-size: 10px;">代理</a> <a href="/tags/%E4%BB%A3%E7%A0%81/" style="font-size: 10px;">代码</a> <a href="/tags/%E4%BB%A3%E7%A0%81%E5%88%86%E4%BA%AB%E5%9B%BE/" style="font-size: 10px;">代码分享图</a> <a href="/tags/%E4%BC%98%E5%8C%96/" style="font-size: 10px;">优化</a> <a href="/tags/%E4%BD%8D%E8%BF%90%E7%AE%97/" style="font-size: 10px;">位运算</a> <a href="/tags/%E5%85%AC%E4%BC%97%E5%8F%B7/" style="font-size: 10px;">公众号</a> <a href="/tags/%E5%88%86%E4%BA%AB/" style="font-size: 10px;">分享</a> <a href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F/" style="font-size: 10px;">分布式</a> <a href="/tags/%E5%88%9B%E4%B8%9A/" style="font-size: 10px;">创业</a> <a href="/tags/%E5%89%8D%E7%AB%AF/" style="font-size: 12.5px;">前端</a> <a href="/tags/%E5%8D%9A%E5%AE%A2/" style="font-size: 10px;">博客</a> <a href="/tags/%E5%8E%9F%E7%94%9FAPP/" style="font-size: 10px;">原生APP</a> <a href="/tags/%E5%8F%8D%E7%88%AC%E8%99%AB/" style="font-size: 12.5px;">反爬虫</a> <a href="/tags/%E5%91%BD%E4%BB%A4/" style="font-size: 10px;">命令</a> <a href="/tags/%E5%93%8D%E5%BA%94%E5%BC%8F%E5%B8%83%E5%B1%80/" style="font-size: 10px;">响应式布局</a> <a href="/tags/%E5%9E%83%E5%9C%BE%E9%82%AE%E4%BB%B6/" style="font-size: 10px;">垃圾邮件</a> <a href="/tags/%E5%9F%9F%E5%90%8D%E7%BB%91%E5%AE%9A/" style="font-size: 10px;">域名绑定</a> <a href="/tags/%E5%A4%8D%E7%9B%98/" style="font-size: 10px;">复盘</a> <a href="/tags/%E5%A4%A7%E4%BC%97%E7%82%B9%E8%AF%84/" style="font-size: 10px;">大众点评</a> <a href="/tags/%E5%AD%97%E4%BD%93%E5%8F%8D%E7%88%AC%E8%99%AB/" style="font-size: 10px;">字体反爬虫</a> <a href="/tags/%E5%AD%97%E7%AC%A6%E9%97%AE%E9%A2%98/" style="font-size: 10px;">字符问题</a> <a href="/tags/%E5%AD%A6%E4%B9%A0%E6%96%B9%E6%B3%95/" style="font-size: 10px;">学习方法</a> <a href="/tags/%E5%AE%89%E5%8D%93/" style="font-size: 10px;">安卓</a> <a href="/tags/%E5%AE%9E%E7%94%A8/" style="font-size: 10px;">实用</a> <a href="/tags/%E5%B0%81%E9%9D%A2/" style="font-size: 10px;">封面</a> <a href="/tags/%E5%B4%94%E5%BA%86%E6%89%8D/" style="font-size: 18.75px;">崔庆才</a> <a href="/tags/%E5%B7%A5%E5%85%B7/" style="font-size: 12.5px;">工具</a> <a href="/tags/%E5%BC%80%E5%8F%91%E5%B7%A5%E5%85%B7/" style="font-size: 10px;">开发工具</a> <a href="/tags/%E5%BE%AE%E8%BD%AF/" style="font-size: 10px;">微软</a> <a href="/tags/%E6%80%9D%E8%80%83/" style="font-size: 10px;">思考</a> <a href="/tags/%E6%89%8B%E6%9C%BA%E8%AE%BF%E9%97%AE/" style="font-size: 10px;">手机访问</a> <a href="/tags/%E6%95%99%E7%A8%8B/" style="font-size: 10px;">教程</a> <a href="/tags/%E6%95%99%E8%82%B2/" style="font-size: 10px;">教育</a> <a href="/tags/%E6%96%B0%E4%B9%A6/" style="font-size: 12.5px;">新书</a> <a href="/tags/%E6%96%B9%E6%B3%95%E8%AE%BA/" style="font-size: 10px;">方法论</a> <a href="/tags/%E6%97%85%E6%B8%B8/" style="font-size: 10px;">旅游</a> <a href="/tags/%E6%97%A5%E5%BF%97/" style="font-size: 10px;">日志</a> <a href="/tags/%E6%9A%97%E6%97%B6%E9%97%B4/" style="font-size: 10px;">暗时间</a> <a href="/tags/%E6%9D%9C%E5%85%B0%E7%89%B9/" style="font-size: 11.25px;">杜兰特</a> <a href="/tags/%E6%A1%8C%E9%9D%A2/" style="font-size: 10px;">桌面</a> <a href="/tags/%E6%AD%8C%E5%8D%95/" style="font-size: 10px;">歌单</a> <a href="/tags/%E6%B1%9F%E5%8D%97/" style="font-size: 10px;">江南</a> <a href="/tags/%E6%B8%B8%E6%88%8F/" style="font-size: 10px;">游戏</a> <a href="/tags/%E7%84%A6%E8%99%91/" style="font-size: 10px;">焦虑</a> <a href="/tags/%E7%88%AC%E8%99%AB/" style="font-size: 16.25px;">爬虫</a> <a href="/tags/%E7%88%AC%E8%99%AB%E4%B9%A6%E7%B1%8D/" style="font-size: 11.25px;">爬虫书籍</a> <a href="/tags/%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F/" style="font-size: 10px;">环境变量</a> <a href="/tags/%E7%94%9F%E6%B4%BB%E7%AC%94%E8%AE%B0/" style="font-size: 10px;">生活笔记</a> <a href="/tags/%E7%99%BB%E5%BD%95/" style="font-size: 10px;">登录</a> <a href="/tags/%E7%9F%A5%E4%B9%8E/" style="font-size: 10px;">知乎</a> <a href="/tags/%E7%9F%AD%E4%BF%A1/" style="font-size: 10px;">短信</a> <a href="/tags/%E7%9F%AD%E4%BF%A1%E9%AA%8C%E8%AF%81%E7%A0%81/" style="font-size: 10px;">短信验证码</a> <a href="/tags/%E7%AC%94%E8%AE%B0%E8%BD%AF%E4%BB%B6/" style="font-size: 10px;">笔记软件</a> <a href="/tags/%E7%AF%AE%E7%BD%91/" style="font-size: 10px;">篮网</a> <a href="/tags/%E7%BA%B8%E5%BC%A0/" style="font-size: 10px;">纸张</a> <a href="/tags/%E7%BB%84%E4%BB%B6/" style="font-size: 10px;">组件</a> <a href="/tags/%E7%BD%91%E7%AB%99/" style="font-size: 10px;">网站</a> <a href="/tags/%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB/" style="font-size: 11.25px;">网络爬虫</a> <a href="/tags/%E7%BE%8E%E5%AD%A6/" style="font-size: 10px;">美学</a> <a href="/tags/%E8%82%89%E5%A4%B9%E9%A6%8D/" style="font-size: 10px;">肉夹馍</a> <a href="/tags/%E8%85%BE%E8%AE%AF%E4%BA%91/" style="font-size: 10px;">腾讯云</a> <a href="/tags/%E8%87%AA%E5%BE%8B/" style="font-size: 10px;">自律</a> <a href="/tags/%E8%A5%BF%E5%B0%91%E7%88%B7/" style="font-size: 10px;">西少爷</a> <a href="/tags/%E8%A7%86%E9%A2%91/" style="font-size: 10px;">视频</a> <a href="/tags/%E8%B0%B7%E6%AD%8C%E9%AA%8C%E8%AF%81%E7%A0%81/" style="font-size: 10px;">谷歌验证码</a> <a href="/tags/%E8%BF%90%E8%90%A5/" style="font-size: 10px;">运营</a> <a href="/tags/%E8%BF%9C%E7%A8%8B/" style="font-size: 10px;">远程</a> <a href="/tags/%E9%80%86%E5%90%91/" style="font-size: 10px;">逆向</a> <a href="/tags/%E9%85%8D%E7%BD%AE/" style="font-size: 10px;">配置</a> <a href="/tags/%E9%87%8D%E8%A3%85/" style="font-size: 10px;">重装</a> <a href="/tags/%E9%98%BF%E6%9D%9C/" style="font-size: 10px;">阿杜</a> <a href="/tags/%E9%9D%99%E8%A7%85/" style="font-size: 17.5px;">静觅</a> <a href="/tags/%E9%A2%A0%E8%A6%86/" style="font-size: 10px;">颠覆</a> <a href="/tags/%E9%A3%9E%E4%BF%A1/" style="font-size: 10px;">飞信</a> <a href="/tags/%E9%B8%BF%E8%92%99/" style="font-size: 10px;">鸿蒙</a>
              </div>
              <script>
                const tagsColors = ['#00a67c', '#5cb85c', '#d9534f', '#567e95', '#b37333', '#f4843d', '#15a287']
                const tagsElements = document.querySelectorAll('.sidebar-panel-tags .content a')
                tagsElements.forEach((item) =>
                {
                  item.style.backgroundColor = tagsColors[Math.floor(Math.random() * tagsColors.length)]
                })

              </script>
            </div>
            <div class="sidebar-panel sidebar-panel-categories sidebar-panel-active">
              <h4 class="name"> 分类 </h4>
              <div class="content">
                <ul class="category-list">
                  <li class="category-list-item"><a class="category-list-link" href="/categories/C-C/">C/C++</a><span class="category-list-count">23</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/HTML/">HTML</a><span class="category-list-count">14</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">5</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">26</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Linux/">Linux</a><span class="category-list-count">15</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Markdown/">Markdown</a><span class="category-list-count">1</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Net/">Net</a><span class="category-list-count">4</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Other/">Other</a><span class="category-list-count">39</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/PHP/">PHP</a><span class="category-list-count">27</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Paper/">Paper</a><span class="category-list-count">2</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/Python/">Python</a><span class="category-list-count">261</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/TypeScript/">TypeScript</a><span class="category-list-count">2</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%AA%E4%BA%BA%E5%B1%95%E7%A4%BA/">个人展示</a><span class="category-list-count">1</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%AA%E4%BA%BA%E6%97%A5%E8%AE%B0/">个人日记</a><span class="category-list-count">9</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%AA%E4%BA%BA%E8%AE%B0%E5%BD%95/">个人记录</a><span class="category-list-count">4</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E4%B8%AA%E4%BA%BA%E9%9A%8F%E7%AC%94/">个人随笔</a><span class="category-list-count">15</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/">安装配置</a><span class="category-list-count">59</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E6%8A%80%E6%9C%AF%E6%9D%82%E8%B0%88/">技术杂谈</a><span class="category-list-count">88</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E6%9C%AA%E5%88%86%E7%B1%BB/">未分类</a><span class="category-list-count">1</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E7%94%9F%E6%B4%BB%E7%AC%94%E8%AE%B0/">生活笔记</a><span class="category-list-count">1</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E7%A6%8F%E5%88%A9%E4%B8%93%E5%8C%BA/">福利专区</a><span class="category-list-count">6</span></li>
                  <li class="category-list-item"><a class="category-list-link" href="/categories/%E8%81%8C%E4%BD%8D%E6%8E%A8%E8%8D%90/">职位推荐</a><span class="category-list-count">2</span></li>
                </ul>
              </div>
            </div>
            <div class="sidebar-panel sidebar-panel-friends sidebar-panel-active">
              <h4 class="name"> 友情链接 </h4>
              <ul class="friends">
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/j2dub.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.findhao.net/" target="_blank" rel="noopener">FindHao</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/ou6mm.jpg">
                  </span>
                  <span class="link">
                    <a href="https://diygod.me/" target="_blank" rel="noopener">DIYgod</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/6apxu.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.51dev.com/" target="_blank" rel="noopener">IT技术社区</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://www.jankl.com/img/titleshu.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.jankl.com/" target="_blank" rel="noopener">liberalist</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/bqlbs.png">
                  </span>
                  <span class="link">
                    <a href="http://www.urselect.com/" target="_blank" rel="noopener">优社电商</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/8s88c.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.yuanrenxue.com/" target="_blank" rel="noopener">猿人学</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/2wgg5.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.yunlifang.cn/" target="_blank" rel="noopener">云立方</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/shwr6.png">
                  </span>
                  <span class="link">
                    <a href="http://lanbing510.info/" target="_blank" rel="noopener">冰蓝</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/blvoh.jpg">
                  </span>
                  <span class="link">
                    <a href="https://lengyue.me/" target="_blank" rel="noopener">冷月</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="http://qianxunclub.com/favicon.png">
                  </span>
                  <span class="link">
                    <a href="http://qianxunclub.com/" target="_blank" rel="noopener">千寻啊千寻</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/0044u.jpg">
                  </span>
                  <span class="link">
                    <a href="http://kodcloud.com/" target="_blank" rel="noopener">可道云</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/ygnpn.jpg">
                  </span>
                  <span class="link">
                    <a href="http://www.kunkundashen.cn/" target="_blank" rel="noopener">坤坤大神</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/22uv1.png">
                  </span>
                  <span class="link">
                    <a href="http://www.cenchong.com/" target="_blank" rel="noopener">岑冲博客</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/ev9kl.png">
                  </span>
                  <span class="link">
                    <a href="http://www.zxiaoji.com/" target="_blank" rel="noopener">张小鸡</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://www.503error.com/favicon.ico">
                  </span>
                  <span class="link">
                    <a href="https://www.503error.com/" target="_blank" rel="noopener">张志明个人博客</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/x714o.jpg">
                  </span>
                  <span class="link">
                    <a href="http://www.hubwiz.com/" target="_blank" rel="noopener">汇智网</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/129d8.png">
                  </span>
                  <span class="link">
                    <a href="https://www.bysocket.com/" target="_blank" rel="noopener">泥瓦匠BYSocket</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://www.xiongge.club/favicon.ico">
                  </span>
                  <span class="link">
                    <a href="https://www.xiongge.club/" target="_blank" rel="noopener">熊哥club</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/3w4fe.png">
                  </span>
                  <span class="link">
                    <a href="https://zerlong.com/" target="_blank" rel="noopener">知语</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/44hxf.png">
                  </span>
                  <span class="link">
                    <a href="http://redstonewill.com/" target="_blank" rel="noopener">红色石头</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/8g1fk.jpg">
                  </span>
                  <span class="link">
                    <a href="http://www.laodong.me/" target="_blank" rel="noopener">老董博客</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/wkaus.jpg">
                  </span>
                  <span class="link">
                    <a href="https://zhaoshuai.me/" target="_blank" rel="noopener">碎念</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/pgo0r.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.chenwenguan.com/" target="_blank" rel="noopener">陈文管的博客</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/kk82a.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.lxlinux.net/" target="_blank" rel="noopener">良许Linux教程网</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/lj0t2.jpg">
                  </span>
                  <span class="link">
                    <a href="https://tanqingbo.cn/" target="_blank" rel="noopener">IT码农</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/i8cdr.png">
                  </span>
                  <span class="link">
                    <a href="https://junyiseo.com/" target="_blank" rel="noopener">均益个人博客</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/chwv2.png">
                  </span>
                  <span class="link">
                    <a href="https://brucedone.com/" target="_blank" rel="noopener">大鱼的鱼塘</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/2y43o.png">
                  </span>
                  <span class="link">
                    <a href="http://bbs.nightteam.cn/" target="_blank" rel="noopener">夜幕爬虫安全论坛</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/zvc3w.jpg">
                  </span>
                  <span class="link">
                    <a href="https://www.weishidong.com/" target="_blank" rel="noopener">韦世东的技术专栏</a>
                  </span>
                </li>
                <li class="friend">
                  <span class="logo">
                    <img src="https://qiniu.cuiqingcai.com/ebudy.jpg">
                  </span>
                  <span class="link">
                    <a href="https://chuanjiabing.com/" target="_blank" rel="noopener">穿甲兵技术社区</a>
                  </span>
                </li>
              </ul>
            </div>
          </div>
        </aside>
        <div id="sidebar-dimmer"></div>
      </div>
    </main>
    <footer class="footer">
      <div class="footer-inner">
        <div class="copyright"> &copy; <span itemprop="copyrightYear">2021</span>
          <span class="with-love">
            <i class="fa fa-heart"></i>
          </span>
          <span class="author" itemprop="copyrightHolder">崔庆才丨静觅</span>
          <span class="post-meta-divider">|</span>
          <span class="post-meta-item-icon">
            <i class="fa fa-chart-area"></i>
          </span>
          <span title="站点总字数">2.6m</span>
          <span class="post-meta-divider">|</span>
          <span class="post-meta-item-icon">
            <i class="fa fa-coffee"></i>
          </span>
          <span title="站点阅读时长">39:54</span>
        </div>
        <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动 </div>
        <div class="beian"><a href="https://beian.miit.gov.cn/" rel="noopener" target="_blank">京ICP备18015597号-1 </a>
        </div>
        <script>
          (function ()
          {
            function leancloudSelector(url)
            {
              url = encodeURI(url);
              return document.getElementById(url).querySelector('.leancloud-visitors-count');
            }

            function addCount(Counter)
            {
              var visitors = document.querySelector('.leancloud_visitors');
              var url = decodeURI(visitors.id);
              var title = visitors.dataset.flagTitle;
              Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify(
              {
                url
              }))).then(response => response.json()).then((
              {
                results
              }) =>
              {
                if (results.length > 0)
                {
                  var counter = results[0];
                  leancloudSelector(url).innerText = counter.time + 1;
                  Counter('put', '/classes/Counter/' + counter.objectId,
                  {
                    time:
                    {
                      '__op': 'Increment',
                      'amount': 1
                    }
                  }).catch(error =>
                  {
                    console.error('Failed to save visitor count', error);
                  });
                }
                else
                {
                  Counter('post', '/classes/Counter',
                  {
                    title,
                    url,
                    time: 1
                  }).then(response => response.json()).then(() =>
                  {
                    leancloudSelector(url).innerText = 1;
                  }).catch(error =>
                  {
                    console.error('Failed to create', error);
                  });
                }
              }).catch(error =>
              {
                console.error('LeanCloud Counter Error', error);
              });
            }

            function showTime(Counter)
            {
              var visitors = document.querySelectorAll('.leancloud_visitors');
              var entries = [...visitors].map(element =>
              {
                return decodeURI(element.id);
              });
              Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify(
              {
                url:
                {
                  '$in': entries
                }
              }))).then(response => response.json()).then((
              {
                results
              }) =>
              {
                for (let url of entries)
                {
                  let target = results.find(item => item.url === url);
                  leancloudSelector(url).innerText = target ? target.time : 0;
                }
              }).catch(error =>
              {
                console.error('LeanCloud Counter Error', error);
              });
            }
            let
            {
              app_id,
              app_key,
              server_url
            } = {
              "enable": true,
              "app_id": "6X5dRQ0pnPWJgYy8SXOg0uID-gzGzoHsz",
              "app_key": "ziLDVEy73ne5HtFTiGstzHMS",
              "server_url": "https://6x5drq0p.lc-cn-n1-shared.com",
              "security": false
            };

            function fetchData(api_server)
            {
              var Counter = (method, url, data) =>
              {
                return fetch(`${api_server}/1.1${url}`,
                {
                  method,
                  headers:
                  {
                    'X-LC-Id': app_id,
                    'X-LC-Key': app_key,
                    'Content-Type': 'application/json',
                  },
                  body: JSON.stringify(data)
                });
              };
              if (CONFIG.page.isPost)
              {
                if (CONFIG.hostname !== location.hostname) return;
                addCount(Counter);
              }
              else if (document.querySelectorAll('.post-title-link').length >= 1)
              {
                showTime(Counter);
              }
            }
            let api_server = app_id.slice(-9) !== '-MdYXbMMI' ? server_url : `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com`;
            if (api_server)
            {
              fetchData(api_server);
            }
            else
            {
              fetch('https://app-router.leancloud.cn/2/route?appId=' + app_id).then(response => response.json()).then((
              {
                api_server
              }) =>
              {
                fetchData('https://' + api_server);
              });
            }
          })();

        </script>
      </div>
      <div class="footer-stat">
        <span id="cnzz_stat_icon_1279355174"></span>
        <script type="text/javascript">
          document.write(unescape("%3Cspan id='cnzz_stat_icon_1279355174'%3E%3C/span%3E%3Cscript src='https://v1.cnzz.com/z_stat.php%3Fid%3D1279355174%26online%3D1%26show%3Dline' type='text/javascript'%3E%3C/script%3E"));

        </script>
      </div>
    </footer>
  </div>
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>
  <script src="/js/utils.js"></script>
  <script src="/.js"></script>
  <script src="/js/schemes/pisces.js"></script>
  <script src="/.js"></script>
  <script src="/js/next-boot.js"></script>
  <script src="/.js"></script>
  <script>
    (function ()
    {
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x = document.getElementsByTagName("link");
      //Find the last canonical URL
      if (x.length > 0)
      {
        for (i = 0; i < x.length; i++)
        {
          if (x[i].rel.toLowerCase() == 'canonical' && x[i].href)
          {
            canonicalURL = x[i].href;
          }
        }
      }
      //Get protocol
      if (!canonicalURL)
      {
        curProtocol = window.location.protocol.split(':')[0];
      }
      else
      {
        curProtocol = canonicalURL.split(':')[0];
      }
      //Get current URL if the canonical URL does not exist
      if (!canonicalURL) canonicalURL = window.location.href;
      //Assign script content. Replace current URL with the canonical URL
      ! function ()
      {
        var e = /([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,
          r = canonicalURL,
          t = document.referrer;
        if (!e.test(r))
        {
          var n = (String(curProtocol).toLowerCase() === 'https') ? "https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif" : "//api.share.baidu.com/s.gif";
          t ? (n += "?r=" + encodeURIComponent(document.referrer), r && (n += "&l=" + r)) : r && (n += "?l=" + r);
          var i = new Image;
          i.src = n
        }
      }(window);
    })();

  </script>
  <script src="/js/local-search.js"></script>
  <script src="/.js"></script>
</body>

</html>
